mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 21:15:45 +00:00
format all files with clang-format (#2471)
* format all files with clang-format * indent c# namespaces Former-commit-id: c66108e7576cd6d938aaa0615718706958d9f474
This commit is contained in:
+154
@@ -153,6 +153,160 @@ StatementMacros:
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
---
|
||||
Language: CSharp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
# AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
---
|
||||
Language: Proto
|
||||
BasedOnStyle: Google
|
||||
AlignConsecutiveDeclarations: true
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ButtonColors
|
||||
{
|
||||
public static ColorBlock SelectedColorBlock()
|
||||
{
|
||||
public class ButtonColors {
|
||||
public static ColorBlock SelectedColorBlock() {
|
||||
ColorBlock block = new ColorBlock();
|
||||
block.colorMultiplier = 1.0f;
|
||||
block.normalColor = Color.gray;
|
||||
@@ -14,8 +12,7 @@ public class ButtonColors
|
||||
return block;
|
||||
}
|
||||
|
||||
public static ColorBlock UnselectedColorBlock()
|
||||
{
|
||||
public static ColorBlock UnselectedColorBlock() {
|
||||
ColorBlock block = new ColorBlock();
|
||||
|
||||
block.colorMultiplier = 1.0f;
|
||||
|
||||
+16
-25
@@ -6,8 +6,7 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
public class AvailableGameItem : MonoBehaviour
|
||||
{
|
||||
public class AvailableGameItem : MonoBehaviour {
|
||||
public GameObject item;
|
||||
public TextMeshProUGUI gameIdField;
|
||||
public eagle.HeroDropdownController heroDropdownController;
|
||||
@@ -20,34 +19,24 @@ public class AvailableGameItem : MonoBehaviour
|
||||
private List<AvailableLeader> availableLeaders;
|
||||
private long gameId;
|
||||
|
||||
public string SelectedLeader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (heroDropdownController.SelectedHeroId == 0)
|
||||
{
|
||||
public string SelectedLeader {
|
||||
get {
|
||||
if (heroDropdownController.SelectedHeroId == 0) {
|
||||
var index = new System.Random().Next(availableLeaders.Count);
|
||||
return availableLeaders[index].Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return availableLeaders[heroDropdownController.SelectedHeroId - 1].Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
void Start() {}
|
||||
|
||||
public void JoinClicked()
|
||||
{
|
||||
JoinCallback(gameId, SelectedLeader);
|
||||
}
|
||||
public void JoinClicked() { JoinCallback(gameId, SelectedLeader); }
|
||||
|
||||
public void SetAvailableNewGame(long gameId, string playersString, List<AvailableLeader> leaders)
|
||||
{
|
||||
public void
|
||||
SetAvailableNewGame(long gameId, string playersString, List<AvailableLeader> leaders) {
|
||||
availableLeaders = leaders;
|
||||
this.gameId = gameId;
|
||||
|
||||
@@ -56,12 +45,14 @@ public class AvailableGameItem : MonoBehaviour
|
||||
joinButton.interactable = true;
|
||||
buttonText.text = "JOIN";
|
||||
|
||||
List<HeroView> heroOptions = new List<HeroView> { new HeroView { Name = "Random", Id = 0, Profession = Net.Eagle0.Eagle.Common.Profession.NoProfession } };
|
||||
for (int i = 0; i < leaders.Count; i++)
|
||||
{
|
||||
List<HeroView> heroOptions = new List<HeroView> { new HeroView {
|
||||
Name = "Random",
|
||||
Id = 0,
|
||||
Profession = Net.Eagle0.Eagle.Common.Profession.NoProfession
|
||||
} };
|
||||
for (int i = 0; i < leaders.Count; i++) {
|
||||
var leader = leaders[i];
|
||||
heroOptions.Add(new HeroView
|
||||
{
|
||||
heroOptions.Add(new HeroView {
|
||||
Name = leader.Name,
|
||||
Profession = leader.Profession,
|
||||
Id = i + 1
|
||||
|
||||
+116
-183
@@ -14,48 +14,61 @@ using System.Threading;
|
||||
using eagle;
|
||||
using TMPro;
|
||||
|
||||
public class AuthInterceptor : Interceptor
|
||||
{
|
||||
public class AuthInterceptor : Interceptor {
|
||||
private readonly string headerName = "Authorization";
|
||||
private string headerValue;
|
||||
|
||||
public AuthInterceptor(String name, String password)
|
||||
{
|
||||
public AuthInterceptor(String name, String password) {
|
||||
String toEncode = name + ":" + password;
|
||||
headerValue = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(toEncode));
|
||||
}
|
||||
public override TResponse BlockingUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, BlockingUnaryCallContinuation<TRequest, TResponse> continuation)
|
||||
{
|
||||
public override TResponse BlockingUnaryCall<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
ClientInterceptorContext<TRequest, TResponse> context,
|
||||
BlockingUnaryCallContinuation<TRequest, TResponse> continuation) {
|
||||
return continuation(request, ContextWithHeaders(context));
|
||||
}
|
||||
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
|
||||
{
|
||||
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
ClientInterceptorContext<TRequest, TResponse> context,
|
||||
AsyncUnaryCallContinuation<TRequest, TResponse> continuation) {
|
||||
return continuation(request, ContextWithHeaders(context));
|
||||
}
|
||||
public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation)
|
||||
{
|
||||
public override AsyncServerStreamingCall<TResponse>
|
||||
AsyncServerStreamingCall<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
ClientInterceptorContext<TRequest, TResponse> context,
|
||||
AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation) {
|
||||
return continuation(request, ContextWithHeaders(context));
|
||||
}
|
||||
public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> context, AsyncClientStreamingCallContinuation<TRequest, TResponse> continuation)
|
||||
{
|
||||
public override AsyncClientStreamingCall<TRequest, TResponse>
|
||||
AsyncClientStreamingCall<TRequest, TResponse>(
|
||||
ClientInterceptorContext<TRequest, TResponse> context,
|
||||
AsyncClientStreamingCallContinuation<TRequest, TResponse> continuation) {
|
||||
return continuation(ContextWithHeaders(context));
|
||||
}
|
||||
public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation<TRequest, TResponse> continuation)
|
||||
{
|
||||
public override AsyncDuplexStreamingCall<TRequest, TResponse>
|
||||
AsyncDuplexStreamingCall<TRequest, TResponse>(
|
||||
ClientInterceptorContext<TRequest, TResponse> context,
|
||||
AsyncDuplexStreamingCallContinuation<TRequest, TResponse> continuation) {
|
||||
return continuation(ContextWithHeaders(context));
|
||||
}
|
||||
|
||||
private ClientInterceptorContext<TRequest, TResponse> ContextWithHeaders<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> original) where TRequest : class where TResponse : class
|
||||
{
|
||||
private ClientInterceptorContext<TRequest, TResponse> ContextWithHeaders<TRequest, TResponse>(
|
||||
ClientInterceptorContext<TRequest, TResponse> original)
|
||||
where TRequest : class
|
||||
where TResponse : class {
|
||||
var headers = new Metadata();
|
||||
headers.Add(headerName, headerValue);
|
||||
|
||||
return new ClientInterceptorContext<TRequest, TResponse>(original.Method, original.Host, original.Options.WithHeaders(headers));
|
||||
return new ClientInterceptorContext<TRequest, TResponse>(
|
||||
original.Method,
|
||||
original.Host,
|
||||
original.Options.WithHeaders(headers));
|
||||
}
|
||||
};
|
||||
|
||||
public class ConnectionHandler : MonoBehaviour
|
||||
{
|
||||
public class ConnectionHandler : MonoBehaviour {
|
||||
public TMP_InputField urlField;
|
||||
public TMP_InputField nameField;
|
||||
public TMP_InputField passwordField;
|
||||
@@ -95,13 +108,13 @@ public class ConnectionHandler : MonoBehaviour
|
||||
const String nameKey = "nameKey";
|
||||
const String passwordKey = "passwordKey";
|
||||
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
var currentResolution = Screen.currentResolution;
|
||||
var resolutions = Screen.resolutions;
|
||||
|
||||
resolutionDropdown.ClearOptions();
|
||||
resolutionDropdown.AddOptions(resolutions.Select(r => $"{r.width} x {r.height} @{r.refreshRate}").ToList());
|
||||
resolutionDropdown.AddOptions(
|
||||
resolutions.Select(r => $"{r.width} x {r.height} @{r.refreshRate}").ToList());
|
||||
resolutionDropdown.value = resolutions.ToList().IndexOf(currentResolution);
|
||||
|
||||
urlField.text = PlayerPrefs.GetString(urlKey, defaultUrl);
|
||||
@@ -118,38 +131,29 @@ public class ConnectionHandler : MonoBehaviour
|
||||
customBattlePanel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void EditorButtonClicked()
|
||||
{
|
||||
SceneManager.LoadScene("Map Editor");
|
||||
}
|
||||
public void EditorButtonClicked() { SceneManager.LoadScene("Map Editor"); }
|
||||
|
||||
public void ConnectEagle()
|
||||
{
|
||||
_internalConnectEagle();
|
||||
}
|
||||
public void ConnectEagle() { _internalConnectEagle(); }
|
||||
|
||||
public void CustomBattle()
|
||||
{
|
||||
_internalCustomBattle();
|
||||
}
|
||||
public void CustomBattle() { _internalCustomBattle(); }
|
||||
|
||||
public void OnApplicationQuit()
|
||||
{
|
||||
if (lobbyUpdatesThread != null)
|
||||
{
|
||||
public void OnApplicationQuit() {
|
||||
if (lobbyUpdatesThread != null) {
|
||||
lobbyUpdatesThread.Abort();
|
||||
lobbyUpdatesThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResolutionChanged(int dropdownIndex)
|
||||
{
|
||||
public void OnResolutionChanged(int dropdownIndex) {
|
||||
var newResolution = Screen.resolutions[dropdownIndex];
|
||||
Screen.SetResolution(newResolution.width, newResolution.height, true, newResolution.refreshRate);
|
||||
Screen.SetResolution(
|
||||
newResolution.width,
|
||||
newResolution.height,
|
||||
true,
|
||||
newResolution.refreshRate);
|
||||
}
|
||||
|
||||
private void _handleGamesReply(GamesReply gamesReply)
|
||||
{
|
||||
private void _handleGamesReply(GamesReply gamesReply) {
|
||||
fetchedRunningGames = new List<Net.Eagle0.Eagle.Api.GameInfo>();
|
||||
fetchedRunningGames.AddRange(gamesReply.RunningGames);
|
||||
|
||||
@@ -158,20 +162,15 @@ public class ConnectionHandler : MonoBehaviour
|
||||
|
||||
fetchedMaxPlayerCount = gamesReply.NewGameOptions.MaxSupportedPlayers;
|
||||
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
MainQueue.Q.Enqueue(() => {
|
||||
awsResourceFetcher.Prefetch(fetchedNewGameLeaders.Select(a => a.ImagePath));
|
||||
|
||||
connectionPanel.gameObject.SetActive(false);
|
||||
gameSelectionPanel.gameObject.SetActive(true);
|
||||
|
||||
// Set up running games table
|
||||
foreach (Transform row in runningGamesListArea.transform)
|
||||
{
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
foreach (var runningGame in gamesReply.RunningGames)
|
||||
{
|
||||
foreach (Transform row in runningGamesListArea.transform) { Destroy(row.gameObject); }
|
||||
foreach (var runningGame in gamesReply.RunningGames) {
|
||||
var listItem = Instantiate(runningGamesListItemPrefab);
|
||||
listItem.transform.SetParent(runningGamesListArea.transform);
|
||||
listItem.transform.localScale = new Vector3 { x = 1.0f, y = 1.0f, z = 1.0f };
|
||||
@@ -182,19 +181,18 @@ public class ConnectionHandler : MonoBehaviour
|
||||
}
|
||||
|
||||
// Set up available/waiting games table
|
||||
foreach (Transform row in availableGamesListArea.transform)
|
||||
{
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
foreach (Transform row in availableGamesListArea.transform) { Destroy(row.gameObject); }
|
||||
|
||||
foreach (var waitingGame in gamesReply.WaitingGames)
|
||||
{
|
||||
foreach (var waitingGame in gamesReply.WaitingGames) {
|
||||
var listItem = Instantiate(waitingGamesListItemPrefab);
|
||||
listItem.transform.SetParent(availableGamesListArea.transform);
|
||||
listItem.transform.localScale = new Vector3 { x = 1.0f, y = 1.0f, z = 1.0f };
|
||||
listItem.GetComponent<WaitingGameItem>().SetWaitingGame(
|
||||
waitingGame.GameId,
|
||||
string.Format("{0} / {1}", waitingGame.CurrentHumanPlayerCount, waitingGame.MaxHumanPlayerCount),
|
||||
string.Format(
|
||||
"{0} / {1}",
|
||||
waitingGame.CurrentHumanPlayerCount,
|
||||
waitingGame.MaxHumanPlayerCount),
|
||||
waitingGame.SelectedLeader);
|
||||
}
|
||||
|
||||
@@ -204,54 +202,44 @@ public class ConnectionHandler : MonoBehaviour
|
||||
createGameItem.transform.localScale = new Vector3 { x = 1.0f, y = 1.0f, z = 1.0f };
|
||||
createGameItem.GetComponent<CreateGameItem>().SetCreationOptions(
|
||||
fetchedNewGameLeaders,
|
||||
fetchedMaxPlayerCount
|
||||
);
|
||||
fetchedMaxPlayerCount);
|
||||
createGameItem.GetComponent<CreateGameItem>().CreateCallback = this.CreateGame;
|
||||
|
||||
foreach (var availableGame in gamesReply.AvailableGames)
|
||||
{
|
||||
foreach (var availableGame in gamesReply.AvailableGames) {
|
||||
var listItem = Instantiate(availableGamesListItemPrefab);
|
||||
listItem.transform.SetParent(availableGamesListArea.transform);
|
||||
listItem.transform.localScale = new Vector3 { x = 1.0f, y = 1.0f, z = 1.0f };
|
||||
listItem.GetComponent<AvailableGameItem>().SetAvailableNewGame(
|
||||
availableGame.GameId,
|
||||
string.Format("{0} / {1}", availableGame.CurrentHumanPlayerCount, availableGame.MaxHumanPlayerCount),
|
||||
string.Format(
|
||||
"{0} / {1}",
|
||||
availableGame.CurrentHumanPlayerCount,
|
||||
availableGame.MaxHumanPlayerCount),
|
||||
availableGame.AvailableLeaders.ToList());
|
||||
listItem.GetComponent<AvailableGameItem>().JoinCallback = this.JoinGame;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void _handleLobbyAction(GamesReply reply, StatusCode sc)
|
||||
{
|
||||
if (sc == StatusCode.OK)
|
||||
{
|
||||
lock (pendingReplyLock)
|
||||
{
|
||||
private void _handleLobbyAction(GamesReply reply, StatusCode sc) {
|
||||
if (sc == StatusCode.OK) {
|
||||
lock (pendingReplyLock) {
|
||||
pendingReply = reply;
|
||||
Monitor.Pulse(pendingReplyLock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// display something
|
||||
}
|
||||
}
|
||||
|
||||
private GamesReply WaitForGamesReply()
|
||||
{
|
||||
lock (pendingReplyLock)
|
||||
{
|
||||
while (listen)
|
||||
{
|
||||
if (pendingReply != null)
|
||||
{
|
||||
private GamesReply WaitForGamesReply() {
|
||||
lock (pendingReplyLock) {
|
||||
while (listen) {
|
||||
if (pendingReply != null) {
|
||||
var reply = pendingReply;
|
||||
pendingReply = null;
|
||||
return reply;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Monitor.Wait(pendingReplyLock);
|
||||
}
|
||||
}
|
||||
@@ -259,27 +247,18 @@ public class ConnectionHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void HandlePendingLobbyUpdates()
|
||||
{
|
||||
public void HandlePendingLobbyUpdates() {
|
||||
listen = true;
|
||||
var _ = eagleConnection.EnterLobby(_handleLobbyAction);
|
||||
|
||||
try
|
||||
{
|
||||
while (listen)
|
||||
{
|
||||
try {
|
||||
while (listen) {
|
||||
var reply = WaitForGamesReply();
|
||||
|
||||
if (reply != null)
|
||||
{
|
||||
_handleGamesReply(reply);
|
||||
if (reply != null) { _handleGamesReply(reply); }
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock (pendingReplyLock)
|
||||
{
|
||||
} finally {
|
||||
lock (pendingReplyLock) {
|
||||
eagleConnection.LeaveLobby();
|
||||
listen = false;
|
||||
pendingReply = null;
|
||||
@@ -287,14 +266,9 @@ public class ConnectionHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void StartListeningForLobbyUpdates()
|
||||
{
|
||||
lock (pendingReplyLock)
|
||||
{
|
||||
if (lobbyUpdatesThread != null)
|
||||
{
|
||||
Debug.Log("Handle updates thread already exists!");
|
||||
}
|
||||
public void StartListeningForLobbyUpdates() {
|
||||
lock (pendingReplyLock) {
|
||||
if (lobbyUpdatesThread != null) { Debug.Log("Handle updates thread already exists!"); }
|
||||
lobbyUpdatesThread = new Thread(HandlePendingLobbyUpdates);
|
||||
lobbyUpdatesThread.Start();
|
||||
|
||||
@@ -302,12 +276,9 @@ public class ConnectionHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void StopListeningForLobbyUpdates()
|
||||
{
|
||||
lock (pendingReplyLock)
|
||||
{
|
||||
if (lobbyUpdatesThread != null)
|
||||
{
|
||||
public void StopListeningForLobbyUpdates() {
|
||||
lock (pendingReplyLock) {
|
||||
if (lobbyUpdatesThread != null) {
|
||||
listen = false;
|
||||
Monitor.Pulse(pendingReplyLock);
|
||||
lobbyUpdatesThread.Join(50);
|
||||
@@ -316,9 +287,7 @@ public class ConnectionHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void _createConnection()
|
||||
{
|
||||
|
||||
private void _createConnection() {
|
||||
PlayerPrefs.SetString(urlKey, urlField.text);
|
||||
PlayerPrefs.SetString(nameKey, nameField.text);
|
||||
PlayerPrefs.SetString(passwordKey, passwordField.text);
|
||||
@@ -326,8 +295,7 @@ public class ConnectionHandler : MonoBehaviour
|
||||
eagleConnection = new EagleConnection(nameField.text, passwordField.text, urlField.text);
|
||||
}
|
||||
|
||||
private void _internalCustomBattle()
|
||||
{
|
||||
private void _internalCustomBattle() {
|
||||
_createConnection();
|
||||
|
||||
setCustomBattleActive(true);
|
||||
@@ -336,128 +304,93 @@ public class ConnectionHandler : MonoBehaviour
|
||||
customBattlePanel.SetActive(true);
|
||||
}
|
||||
|
||||
private void _internalConnectEagle()
|
||||
{
|
||||
private void _internalConnectEagle() {
|
||||
setLobbyActive(true);
|
||||
|
||||
_createConnection();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
StartListeningForLobbyUpdates();
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
errorPanel.Add(e);
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
errorPanel.Add(e);
|
||||
});
|
||||
} catch (RpcException e) {
|
||||
MainQueue.Q.Enqueue(() => { errorPanel.Add(e); });
|
||||
} catch (Exception e) {
|
||||
MainQueue.Q.Enqueue(() => { errorPanel.Add(e); });
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinGame(long gameId, string leaderName)
|
||||
{
|
||||
public void JoinGame(long gameId, string leaderName) {
|
||||
var game = _internalJoinEagleGame(gameId, leaderName);
|
||||
}
|
||||
|
||||
public void CreateGame(string leaderName, int humanPlayerCount, int totalPlayerCount)
|
||||
{
|
||||
public void CreateGame(string leaderName, int humanPlayerCount, int totalPlayerCount) {
|
||||
var game = _internalCreateGame(leaderName, humanPlayerCount, totalPlayerCount);
|
||||
}
|
||||
|
||||
public void QuitButtonClicked()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
public void QuitButtonClicked() { Application.Quit(); }
|
||||
|
||||
private void _handleJoinGameResponse(JoinGameResponse response)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (response.Result)
|
||||
{
|
||||
case JoinGameResult.SuccessJoinGameResult:
|
||||
break;
|
||||
private void _handleJoinGameResponse(JoinGameResponse response) {
|
||||
try {
|
||||
switch (response.Result) {
|
||||
case JoinGameResult.SuccessJoinGameResult: break;
|
||||
|
||||
default:
|
||||
// FIXME: display something
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
} catch (Exception e) { Console.WriteLine(e.ToString()); }
|
||||
}
|
||||
|
||||
private async Task _internalCreateGame(string desiredLeader, int humanPlayerCount, int totalPlayerCount)
|
||||
{
|
||||
try
|
||||
{
|
||||
private async Task
|
||||
_internalCreateGame(string desiredLeader, int humanPlayerCount, int totalPlayerCount) {
|
||||
try {
|
||||
var joinGameResponse = await eagleConnection.EagleGrpcClient.CreateGameAsync(
|
||||
new CreateGameRequest
|
||||
{
|
||||
new CreateGameRequest {
|
||||
DesiredLeader = desiredLeader,
|
||||
TotalPlayerCount = totalPlayerCount,
|
||||
HumanPlayerCount = humanPlayerCount
|
||||
},
|
||||
cancellationToken: EagleConnection.EagleCancellationToken
|
||||
);
|
||||
cancellationToken: EagleConnection.EagleCancellationToken);
|
||||
|
||||
_handleJoinGameResponse(joinGameResponse);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
} catch (WebException e) {
|
||||
Debug.Log(String.Format("Caught exception in BeginGetResponse {0}", e.Message));
|
||||
setLobbyActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task _internalJoinEagleGame(long gameId, string leaderName)
|
||||
{
|
||||
try
|
||||
{
|
||||
private async Task _internalJoinEagleGame(long gameId, string leaderName) {
|
||||
try {
|
||||
var joinGameResponse = await eagleConnection.EagleGrpcClient.JoinGameAsync(
|
||||
new JoinGameRequest { GameId = gameId, DesiredLeader = leaderName },
|
||||
cancellationToken: EagleConnection.EagleCancellationToken
|
||||
);
|
||||
cancellationToken: EagleConnection.EagleCancellationToken);
|
||||
|
||||
_handleJoinGameResponse(joinGameResponse);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
} catch (WebException e) {
|
||||
Debug.Log(String.Format("Caught exception in BeginGetResponse {0}", e.Message));
|
||||
setLobbyActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLobbyActive(bool active)
|
||||
{
|
||||
private void setLobbyActive(bool active) {
|
||||
runningGamesListArea.SetActive(active);
|
||||
availableGamesListArea.SetActive(active);
|
||||
StopListeningForLobbyUpdates();
|
||||
}
|
||||
|
||||
private void setCustomBattleActive(bool active)
|
||||
{
|
||||
private void setCustomBattleActive(bool active) {
|
||||
StopListeningForLobbyUpdates();
|
||||
|
||||
customBattleHandler.SetActive(eagleConnection);
|
||||
}
|
||||
|
||||
public void SelectEagleGame(long gameId)
|
||||
{
|
||||
public void SelectEagleGame(long gameId) {
|
||||
setLobbyActive(false);
|
||||
var gameInfo = fetchedRunningGames.Find(gi => gi.GameId == gameId);
|
||||
|
||||
eagleCanvas.GetComponent<EagleGameController>().SetUpGame(gameInfo.GameId, gameInfo.FactionId, eagleConnection);
|
||||
eagleCanvas.GetComponent<EagleGameController>().SetUpGame(
|
||||
gameInfo.GameId,
|
||||
gameInfo.FactionId,
|
||||
eagleConnection);
|
||||
connectionCanvas.enabled = false;
|
||||
connectionCanvas.gameObject.SetActive(false);
|
||||
eagleCanvas.gameObject.SetActive(true);
|
||||
|
||||
+29
-42
@@ -6,8 +6,7 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
public class CreateGameItem : MonoBehaviour
|
||||
{
|
||||
public class CreateGameItem : MonoBehaviour {
|
||||
public eagle.HeroDropdownController heroDropdownController;
|
||||
public TMP_Dropdown totalHumansDropdown;
|
||||
public TMP_Dropdown totalPlayersDropdown;
|
||||
@@ -18,64 +17,53 @@ public class CreateGameItem : MonoBehaviour
|
||||
|
||||
private List<AvailableLeader> availableLeaders;
|
||||
|
||||
public string SelectedLeader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (heroDropdownController.SelectedHeroId == 0)
|
||||
{
|
||||
public string SelectedLeader {
|
||||
get {
|
||||
if (heroDropdownController.SelectedHeroId == 0) {
|
||||
var index = new System.Random().Next(availableLeaders.Count);
|
||||
return availableLeaders[index].Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return availableLeaders[heroDropdownController.SelectedHeroId - 1].Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
void Start() {}
|
||||
|
||||
public void LeaderDropdownSelected(TMP_Dropdown dropdown) {}
|
||||
|
||||
public void TotalPlayersDropdownSelected(TMP_Dropdown dropdown) { SetHumanPlayersDropdown(); }
|
||||
|
||||
public void CreateClicked() {
|
||||
CreateCallback(
|
||||
SelectedLeader,
|
||||
totalHumansDropdown.value + 1,
|
||||
totalPlayersDropdown.value + 1);
|
||||
}
|
||||
|
||||
public void LeaderDropdownSelected(TMP_Dropdown dropdown)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void TotalPlayersDropdownSelected(TMP_Dropdown dropdown)
|
||||
{
|
||||
SetHumanPlayersDropdown();
|
||||
}
|
||||
|
||||
public void CreateClicked()
|
||||
{
|
||||
CreateCallback(SelectedLeader, totalHumansDropdown.value + 1, totalPlayersDropdown.value + 1);
|
||||
}
|
||||
|
||||
public void SetHumanPlayersDropdown()
|
||||
{
|
||||
public void SetHumanPlayersDropdown() {
|
||||
var currentValue = totalHumansDropdown.value;
|
||||
totalHumansDropdown.ClearOptions();
|
||||
totalHumansDropdown.AddOptions(
|
||||
Enumerable.Range(1, totalPlayersDropdown.value + 1).Select(i => i.ToString()).ToList()
|
||||
);
|
||||
totalHumansDropdown.AddOptions(Enumerable.Range(1, totalPlayersDropdown.value + 1)
|
||||
.Select(i => i.ToString())
|
||||
.ToList());
|
||||
totalHumansDropdown.value = Math.Min(totalPlayersDropdown.value, currentValue);
|
||||
}
|
||||
|
||||
public void SetCreationOptions(List<AvailableLeader> leaders, int maxPlayerCount)
|
||||
{
|
||||
public void SetCreationOptions(List<AvailableLeader> leaders, int maxPlayerCount) {
|
||||
this.availableLeaders = leaders;
|
||||
|
||||
buttonText.text = "CREATE";
|
||||
|
||||
List<HeroView> heroOptions = new List<HeroView> { new HeroView { Name = "Random", Id = 0, Profession = Net.Eagle0.Eagle.Common.Profession.NoProfession } };
|
||||
for (int i = 0; i < leaders.Count; i++)
|
||||
{
|
||||
List<HeroView> heroOptions = new List<HeroView> { new HeroView {
|
||||
Name = "Random",
|
||||
Id = 0,
|
||||
Profession = Net.Eagle0.Eagle.Common.Profession.NoProfession
|
||||
} };
|
||||
for (int i = 0; i < leaders.Count; i++) {
|
||||
var leader = leaders[i];
|
||||
heroOptions.Add(new HeroView
|
||||
{
|
||||
heroOptions.Add(new HeroView {
|
||||
Name = leader.Name,
|
||||
Profession = leader.Profession,
|
||||
Id = i + 1,
|
||||
@@ -88,8 +76,7 @@ public class CreateGameItem : MonoBehaviour
|
||||
|
||||
totalPlayersDropdown.ClearOptions();
|
||||
totalPlayersDropdown.AddOptions(
|
||||
Enumerable.Range(1, maxPlayerCount).Select(i => i.ToString()).ToList()
|
||||
);
|
||||
Enumerable.Range(1, maxPlayerCount).Select(i => i.ToString()).ToList());
|
||||
totalPlayersDropdown.value = Math.Min(6, maxPlayerCount - 1);
|
||||
|
||||
SetHumanPlayersDropdown();
|
||||
|
||||
+136
-194
@@ -16,8 +16,7 @@ using UnityEngine.UI;
|
||||
using Grpc.Core;
|
||||
using static Net.Eagle0.Eagle.Api.UpdateStreamRequest.Types;
|
||||
|
||||
public class CustomBattleHandler : MonoBehaviour
|
||||
{
|
||||
public class CustomBattleHandler : MonoBehaviour {
|
||||
public GameObject yourArmiesArea;
|
||||
public GameObject aiArmiesArea;
|
||||
public Canvas shardokCanvas;
|
||||
@@ -46,27 +45,26 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
private AWSResourceFetcher resourceFetcher;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
void Start() {}
|
||||
|
||||
public void SetActive(EagleConnection conn)
|
||||
{
|
||||
public void SetActive(EagleConnection conn) {
|
||||
eagleConnection = conn;
|
||||
resourceFetcher = GetComponent<AWSResourceFetcher>();
|
||||
resourceFetcher.EagleConnection = conn;
|
||||
|
||||
var random = new System.Random();
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
string gameId = new string(Enumerable.Repeat(chars, 25).Select(s => s[random.Next(s.Length)]).ToArray());
|
||||
string gameId = new string(
|
||||
Enumerable.Repeat(chars, 25).Select(s => s[random.Next(s.Length)]).ToArray());
|
||||
|
||||
gameRequest = new Net.Eagle0.Common.NewGameRequest
|
||||
{
|
||||
gameRequest = new Net.Eagle0.Common.NewGameRequest {
|
||||
GameId = gameId,
|
||||
Month = monthDropdown.value + 1
|
||||
};
|
||||
|
||||
MapNames = eagleConnection.EagleGrpcClient.GetHexMapNames(new Net.Eagle0.Eagle.Api.HexMapNamesRequest()).MapNames.ToList();
|
||||
MapNames = eagleConnection.EagleGrpcClient
|
||||
.GetHexMapNames(new Net.Eagle0.Eagle.Api.HexMapNamesRequest())
|
||||
.MapNames.ToList();
|
||||
MapNames.Sort();
|
||||
|
||||
mapDropdown.options = MapNames.Select(name => new TMP_Dropdown.OptionData(name)).ToList();
|
||||
@@ -77,18 +75,15 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
|
||||
AddAIArmy();
|
||||
aiArmiesArea.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
public async void StartCustomBattle()
|
||||
{
|
||||
public async void StartCustomBattle() {
|
||||
Dictionary<int, string> heroNames = new Dictionary<int, string>();
|
||||
int nextEagleHeroId = 1;
|
||||
|
||||
bool youAreDefender = defenderToggle.isOn;
|
||||
|
||||
var yourSetupInfo = new Net.Eagle0.Common.PlayerSetupInfo
|
||||
{
|
||||
var yourSetupInfo = new Net.Eagle0.Common.PlayerSetupInfo {
|
||||
UserName = eagleConnection.PlayerName,
|
||||
Defender = youAreDefender,
|
||||
EagleFactionId = 1,
|
||||
@@ -97,18 +92,15 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
};
|
||||
|
||||
yourSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.LastPlayerStanding);
|
||||
if (youAreDefender)
|
||||
{
|
||||
yourSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.WinAfterMaxRounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
yourSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.HoldsCriticalTiles);
|
||||
if (youAreDefender) {
|
||||
yourSetupInfo.VictoryConditions.Add(
|
||||
Net.Eagle0.Common.VictoryCondition.WinAfterMaxRounds);
|
||||
} else {
|
||||
yourSetupInfo.VictoryConditions.Add(
|
||||
Net.Eagle0.Common.VictoryCondition.HoldsCriticalTiles);
|
||||
}
|
||||
|
||||
for (int i = 0; i < yourUnitsController.RowCount; i++)
|
||||
{
|
||||
|
||||
for (int i = 0; i < yourUnitsController.RowCount; i++) {
|
||||
var unit = yourUnitsController.ComponentAt<CustomUnitRowController>(i).Unit;
|
||||
unit.Hero.EagleHeroId = nextEagleHeroId;
|
||||
yourSetupInfo.Units.Add(unit);
|
||||
@@ -116,8 +108,7 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
nextEagleHeroId++;
|
||||
}
|
||||
|
||||
var aiSetupInfo = new Net.Eagle0.Common.PlayerSetupInfo
|
||||
{
|
||||
var aiSetupInfo = new Net.Eagle0.Common.PlayerSetupInfo {
|
||||
UserName = "AI",
|
||||
Defender = !youAreDefender,
|
||||
EagleFactionId = 2,
|
||||
@@ -126,17 +117,14 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
};
|
||||
|
||||
aiSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.LastPlayerStanding);
|
||||
if (youAreDefender)
|
||||
{
|
||||
aiSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.HoldsCriticalTiles);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (youAreDefender) {
|
||||
aiSetupInfo.VictoryConditions.Add(
|
||||
Net.Eagle0.Common.VictoryCondition.HoldsCriticalTiles);
|
||||
} else {
|
||||
aiSetupInfo.VictoryConditions.Add(Net.Eagle0.Common.VictoryCondition.WinAfterMaxRounds);
|
||||
}
|
||||
|
||||
for (int i = 0; i < aiUnitsController.RowCount; i++)
|
||||
{
|
||||
for (int i = 0; i < aiUnitsController.RowCount; i++) {
|
||||
var unit = aiUnitsController.ComponentAt<CustomUnitRowController>(i).Unit;
|
||||
unit.Hero.EagleHeroId = nextEagleHeroId;
|
||||
aiSetupInfo.Units.Add(unit);
|
||||
@@ -148,43 +136,36 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
|
||||
gameRequest.UserInfos.Clear();
|
||||
List<Net.Eagle0.Common.PlayerSetupInfo> userInfos =
|
||||
youAreDefender ?
|
||||
new List<Net.Eagle0.Common.PlayerSetupInfo>()
|
||||
{
|
||||
aiSetupInfo,
|
||||
yourSetupInfo
|
||||
} : new List<Net.Eagle0.Common.PlayerSetupInfo>()
|
||||
{
|
||||
youAreDefender ? new List<Net.Eagle0.Common
|
||||
.PlayerSetupInfo>() { aiSetupInfo, yourSetupInfo }
|
||||
: new List<Net.Eagle0.Common.PlayerSetupInfo>() {
|
||||
yourSetupInfo,
|
||||
aiSetupInfo
|
||||
};
|
||||
gameRequest.UserInfos.Add(userInfos);
|
||||
|
||||
var newGameResponse = eagleConnection.EagleGrpcClient.CreateCustomBattle(new CustomBattleRequest { NewGameRequest = gameRequest });
|
||||
var newGameResponse = eagleConnection.EagleGrpcClient.CreateCustomBattle(
|
||||
new CustomBattleRequest { NewGameRequest = gameRequest });
|
||||
|
||||
Int16 yourPid = (Int16)(youAreDefender ? 1 : 0);
|
||||
|
||||
HexMap map = null;
|
||||
|
||||
if (gameRequest.CustomMapBytes.IsEmpty)
|
||||
{
|
||||
map = (await eagleConnection.EagleGrpcClient.GetHexMapAsync(new HexMapRequest { MapName = gameRequest.HexMapName })).Map;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gameRequest.CustomMapBytes.IsEmpty) {
|
||||
map = (await eagleConnection.EagleGrpcClient.GetHexMapAsync(
|
||||
new HexMapRequest { MapName = gameRequest.HexMapName }))
|
||||
.Map;
|
||||
} else {
|
||||
map = HexMap.Parser.ParseFrom(gameRequest.CustomMapBytes);
|
||||
}
|
||||
|
||||
var players = new List<ShardokGameModel.PlayerWithHostility>()
|
||||
{
|
||||
new ShardokGameModel.PlayerWithHostility
|
||||
{
|
||||
var players = new List<ShardokGameModel.PlayerWithHostility>() {
|
||||
new ShardokGameModel.PlayerWithHostility {
|
||||
playerId = yourPid,
|
||||
factionName = "You",
|
||||
hostility = Net.Eagle0.Common.Hostility.SelfHostility
|
||||
},
|
||||
new ShardokGameModel.PlayerWithHostility
|
||||
{
|
||||
new ShardokGameModel.PlayerWithHostility {
|
||||
playerId = youAreDefender ? 0 : 1,
|
||||
factionName = "AI",
|
||||
hostility = Net.Eagle0.Common.Hostility.EnemyHostility
|
||||
@@ -206,40 +187,40 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
players: players,
|
||||
heroNames: heroNames,
|
||||
battalionNames: new Dictionary<int, string> { { 0, "no name" } },
|
||||
headshotFetcher: (id) => resourceFetcher.GetImage("no_profession/male/000107.1333771077.png"));
|
||||
headshotFetcher: (id) =>
|
||||
resourceFetcher.GetImage("no_profession/male/000107.1333771077.png"));
|
||||
|
||||
shardokCanvas.gameObject.SetActive(true);
|
||||
shardokCanvas.GetComponent<ShardokGameController>().SetUpGame(shardokModel);
|
||||
|
||||
clientInterface = new RemoteEagleClient(newGameResponse.EagleGameId, eagleConnection.EagleGrpcClient, eagleConnection.Credentials, 1, EagleConnection.EagleCancellationToken);
|
||||
clientInterface = new RemoteEagleClient(
|
||||
newGameResponse.EagleGameId,
|
||||
eagleConnection.EagleGrpcClient,
|
||||
eagleConnection.Credentials,
|
||||
1,
|
||||
EagleConnection.EagleCancellationToken);
|
||||
Register();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Register()
|
||||
{
|
||||
clientInterface.RegisterForUpdates(callback, 0, new List<ShardokViewStatus> {
|
||||
new ShardokViewStatus
|
||||
{
|
||||
private void Register() {
|
||||
clientInterface.RegisterForUpdates(
|
||||
callback,
|
||||
0,
|
||||
new List<ShardokViewStatus> { new ShardokViewStatus {
|
||||
ShardokGameId = shardokModel.GameId,
|
||||
FilteredResultCount = shardokModel.History.Count
|
||||
}
|
||||
});
|
||||
} });
|
||||
}
|
||||
|
||||
void callback(UpdateStreamResponse response, StatusCode statusCode)
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
void callback(UpdateStreamResponse response, StatusCode statusCode) {
|
||||
if (response == null) {
|
||||
Register();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (response.ResponseDetailsCase)
|
||||
{
|
||||
} else {
|
||||
switch (response.ResponseDetailsCase) {
|
||||
case UpdateStreamResponse.ResponseDetailsOneofCase.ShardokActionResultResponse:
|
||||
foreach (var resp in response.ShardokActionResultResponse.ShardokGameResponses)
|
||||
{
|
||||
foreach (var resp in response.ShardokActionResultResponse
|
||||
.ShardokGameResponses) {
|
||||
shardokModel.HandleUpdates(resp.ActionResultViews, resp.NewResultViewCount);
|
||||
shardokModel.HandleAvailableCommands(resp.AvailableCommands);
|
||||
}
|
||||
@@ -251,13 +232,11 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUpMap(HexMap hexMap, string mapName, Google.Protobuf.ByteString mapBytes)
|
||||
{
|
||||
private void SetUpMap(HexMap hexMap, string mapName, Google.Protobuf.ByteString mapBytes) {
|
||||
attackerStartingPositions = new List<int>();
|
||||
for (int i = 0; i < hexMap.AttackerStartingPositions.Count; i++)
|
||||
{
|
||||
if (hexMap.AttackerStartingPositions[i] != null && hexMap.AttackerStartingPositions[i].Positions.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < hexMap.AttackerStartingPositions.Count; i++) {
|
||||
if (hexMap.AttackerStartingPositions[i] != null &&
|
||||
hexMap.AttackerStartingPositions[i].Positions.Count > 0) {
|
||||
attackerStartingPositions.Add(i);
|
||||
}
|
||||
}
|
||||
@@ -267,74 +246,65 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
UpdateStartingPositions();
|
||||
}
|
||||
|
||||
public void MapSelected(int index)
|
||||
{
|
||||
public void MapSelected(int index) {
|
||||
string mapName = MapNames[index];
|
||||
|
||||
var mapResponse = eagleConnection.EagleGrpcClient.GetHexMap(new Net.Eagle0.Eagle.Api.HexMapRequest
|
||||
{
|
||||
MapName = mapName
|
||||
});
|
||||
var mapResponse = eagleConnection.EagleGrpcClient.GetHexMap(
|
||||
new Net.Eagle0.Eagle.Api.HexMapRequest { MapName = mapName });
|
||||
|
||||
SetUpMap(mapResponse.Map, mapName, Google.Protobuf.ByteString.Empty);
|
||||
}
|
||||
|
||||
public void DefenderToggleClicked()
|
||||
{
|
||||
UpdateStartingPositions();
|
||||
public void DefenderToggleClicked() { UpdateStartingPositions(); }
|
||||
|
||||
public void UpdateStartingPositions() {
|
||||
var yourStartingPositions =
|
||||
defenderToggle.isOn ? defenderStartingPositions : attackerStartingPositions;
|
||||
for (int i = 0; i < yourUnitsController.RowCount; i++) {
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions =
|
||||
yourStartingPositions;
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).startingPosition.value =
|
||||
i / 10;
|
||||
}
|
||||
|
||||
public void UpdateStartingPositions()
|
||||
{
|
||||
var yourStartingPositions = defenderToggle.isOn ? defenderStartingPositions : attackerStartingPositions;
|
||||
for (int i = 0; i < yourUnitsController.RowCount; i++)
|
||||
{
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions = yourStartingPositions;
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).startingPosition.value = i / 10;
|
||||
}
|
||||
|
||||
var aiStartingPositions = defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
for (int i = 0; i < aiUnitsController.RowCount; i++)
|
||||
{
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions = aiStartingPositions;
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).startingPosition.value = i / 10;
|
||||
var aiStartingPositions =
|
||||
defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
for (int i = 0; i < aiUnitsController.RowCount; i++) {
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions =
|
||||
aiStartingPositions;
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).startingPosition.value =
|
||||
i / 10;
|
||||
}
|
||||
}
|
||||
|
||||
private static int nextStartingPositionIndex(int startingPositionCount, EventBasedTable unitsTable)
|
||||
{
|
||||
private static int nextStartingPositionIndex(
|
||||
int startingPositionCount,
|
||||
EventBasedTable unitsTable) {
|
||||
int[] currentCounts = new int[startingPositionCount];
|
||||
for (int i = 0; i < unitsTable.RowCount; i++)
|
||||
{
|
||||
currentCounts[unitsTable.ComponentAt<CustomUnitRowController>(i).startingPosition.value]++;
|
||||
for (int i = 0; i < unitsTable.RowCount; i++) {
|
||||
currentCounts[unitsTable.ComponentAt<CustomUnitRowController>(i)
|
||||
.startingPosition.value]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < startingPositionCount; i++)
|
||||
{
|
||||
if (currentCounts[i] < 10)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
for (int i = 0; i < startingPositionCount; i++) {
|
||||
if (currentCounts[i] < 10) { return i; }
|
||||
}
|
||||
// we couldn't find an available starting position
|
||||
throw new ArgumentException("too many units");
|
||||
}
|
||||
|
||||
public void AddYourArmy()
|
||||
{
|
||||
public void AddYourArmy() {
|
||||
int index = yourUnitsController.RowCount;
|
||||
|
||||
List<int> startingPositions;
|
||||
int nextStartingPos;
|
||||
if (defenderToggle.isOn)
|
||||
{
|
||||
if (defenderToggle.isOn) {
|
||||
startingPositions = defenderStartingPositions;
|
||||
nextStartingPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
startingPositions = attackerStartingPositions;
|
||||
nextStartingPos = nextStartingPositionIndex(startingPositions.Count, yourUnitsController);
|
||||
nextStartingPos =
|
||||
nextStartingPositionIndex(startingPositions.Count, yourUnitsController);
|
||||
}
|
||||
|
||||
var row = yourUnitsController.AddRowWithComponent<CustomUnitRowController>();
|
||||
@@ -342,19 +312,15 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
row.startingPosition.value = nextStartingPos;
|
||||
}
|
||||
|
||||
public void AddAIArmy()
|
||||
{
|
||||
public void AddAIArmy() {
|
||||
int index = aiUnitsController.RowCount;
|
||||
|
||||
List<int> startingPositions;
|
||||
int nextStartingPos;
|
||||
if (defenderToggle.isOn)
|
||||
{
|
||||
if (defenderToggle.isOn) {
|
||||
startingPositions = attackerStartingPositions;
|
||||
nextStartingPos = nextStartingPositionIndex(startingPositions.Count, aiUnitsController);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
startingPositions = defenderStartingPositions;
|
||||
nextStartingPos = 0;
|
||||
}
|
||||
@@ -364,53 +330,43 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
row.startingPosition.value = nextStartingPos;
|
||||
}
|
||||
|
||||
public void LoadGameRequest()
|
||||
{
|
||||
StartCoroutine(ShowLoadGameRequestCoroutine());
|
||||
}
|
||||
public void LoadGameRequest() { StartCoroutine(ShowLoadGameRequestCoroutine()); }
|
||||
|
||||
private void LoadGameRequest(Net.Eagle0.Common.NewGameRequest request)
|
||||
{
|
||||
private void LoadGameRequest(Net.Eagle0.Common.NewGameRequest request) {
|
||||
var gameId = request.GameId + gameRequest.GameId;
|
||||
gameRequest = request;
|
||||
gameRequest.GameId = gameId;
|
||||
|
||||
monthDropdown.value = gameRequest.Month - 1;
|
||||
mapDropdown.value = mapDropdown.options.Select(opt => opt.text).ToList().IndexOf(gameRequest.HexMapName);
|
||||
mapDropdown.value = mapDropdown.options.Select(opt => opt.text)
|
||||
.ToList()
|
||||
.IndexOf(gameRequest.HexMapName);
|
||||
MapSelected(mapDropdown.value);
|
||||
|
||||
// FIXME: two hardcoded players
|
||||
var yourInfo = gameRequest.UserInfos.Last();
|
||||
var aiInfo = gameRequest.UserInfos.First();
|
||||
|
||||
if (!yourInfo.Defender)
|
||||
{
|
||||
throw new ArgumentException("Second player must be defender");
|
||||
}
|
||||
if (!yourInfo.Defender) { throw new ArgumentException("Second player must be defender"); }
|
||||
defenderToggle.isOn = true;
|
||||
|
||||
// FIXME: put some of this stuff straight into the gameinfo
|
||||
yourUnitsController.RowCount = yourInfo.Units.Count();
|
||||
for (int i = 0; i < yourInfo.Units.Count(); i++)
|
||||
{
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions = defenderToggle.isOn
|
||||
? defenderStartingPositions
|
||||
: attackerStartingPositions;
|
||||
for (int i = 0; i < yourInfo.Units.Count(); i++) {
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions =
|
||||
defenderToggle.isOn ? defenderStartingPositions : attackerStartingPositions;
|
||||
yourUnitsController.ComponentAt<CustomUnitRowController>(i).Unit = yourInfo.Units[i];
|
||||
}
|
||||
|
||||
aiUnitsController.RowCount = aiInfo.Units.Count();
|
||||
for (int i = 0; i < aiInfo.Units.Count(); i++)
|
||||
{
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions = defenderToggle.isOn
|
||||
? attackerStartingPositions
|
||||
: defenderStartingPositions;
|
||||
for (int i = 0; i < aiInfo.Units.Count(); i++) {
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).AvailableStartingPositions =
|
||||
defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
aiUnitsController.ComponentAt<CustomUnitRowController>(i).Unit = aiInfo.Units[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void PerfButtonClicked()
|
||||
{
|
||||
public void PerfButtonClicked() {
|
||||
var index = MapNames.IndexOf("Alah");
|
||||
mapDropdown.value = index;
|
||||
MapSelected(index);
|
||||
@@ -418,21 +374,21 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
yourUnitsController.RowCount = 0;
|
||||
aiUnitsController.RowCount = 0;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
var rowIndex = i;
|
||||
|
||||
var aiRow = aiUnitsController.AddRowWithComponent<CustomUnitRowController>();
|
||||
aiRow.AvailableStartingPositions = defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
aiRow.AvailableStartingPositions =
|
||||
defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
aiRow.professionDropdown.value = i + 1;
|
||||
|
||||
var yourRow = yourUnitsController.AddRowWithComponent<CustomUnitRowController>();
|
||||
yourRow.AvailableStartingPositions = defenderToggle.isOn ? defenderStartingPositions : attackerStartingPositions;
|
||||
yourRow.AvailableStartingPositions =
|
||||
defenderToggle.isOn ? defenderStartingPositions : attackerStartingPositions;
|
||||
}
|
||||
}
|
||||
|
||||
public void RiversButtonClicked()
|
||||
{
|
||||
public void RiversButtonClicked() {
|
||||
var index = MapNames.IndexOf("Chipingia");
|
||||
mapDropdown.value = index;
|
||||
MapSelected(index);
|
||||
@@ -442,51 +398,41 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
var firstRow = aiUnitsController.AddRowWithComponent<CustomUnitRowController>();
|
||||
firstRow.SelectedProfession = Net.Eagle0.Common.CommonProfession.Engineer;
|
||||
firstRow.SelectedBattalionTypeId = Net.Eagle0.Common.CommonBattalionTypeId.HeavyInfantry;
|
||||
firstRow.AvailableStartingPositions = defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
firstRow.AvailableStartingPositions =
|
||||
defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
|
||||
for (int i = 1; i < 5; i++)
|
||||
{
|
||||
for (int i = 1; i < 5; i++) {
|
||||
var rowIndex = i;
|
||||
|
||||
var row = aiUnitsController.AddRowWithComponent<CustomUnitRowController>();
|
||||
row.SelectedBattalionTypeId = Net.Eagle0.Common.CommonBattalionTypeId.HeavyCavalry;
|
||||
row.AvailableStartingPositions = defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
row.AvailableStartingPositions =
|
||||
defenderToggle.isOn ? attackerStartingPositions : defenderStartingPositions;
|
||||
}
|
||||
}
|
||||
|
||||
public void CustomMapToggleClicked()
|
||||
{
|
||||
public void CustomMapToggleClicked() {
|
||||
chooseMapButton.gameObject.SetActive(customMapToggle.isOn);
|
||||
mapDropdown.gameObject.SetActive(!customMapToggle.isOn);
|
||||
|
||||
if (customMapToggle.isOn)
|
||||
{
|
||||
if (gameRequest.CustomMapBytes.IsEmpty)
|
||||
{
|
||||
ChooseCustomMapButtonClicked();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (customMapToggle.isOn) {
|
||||
if (gameRequest.CustomMapBytes.IsEmpty) { ChooseCustomMapButtonClicked(); }
|
||||
} else {
|
||||
gameRequest.CustomMapBytes = ByteString.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChooseCustomMapButtonClicked()
|
||||
{
|
||||
StartCoroutine(ShowLoadCustomMapCoroutine());
|
||||
}
|
||||
public void ChooseCustomMapButtonClicked() { StartCoroutine(ShowLoadCustomMapCoroutine()); }
|
||||
|
||||
IEnumerator ShowLoadGameRequestCoroutine()
|
||||
{
|
||||
IEnumerator ShowLoadGameRequestCoroutine() {
|
||||
var initialPath = PlayerPrefs.GetString("gameRequestLocation", null);
|
||||
|
||||
FileBrowser.SetFilters(true, new FileBrowser.Filter("Game Requests", ".e0gr"));
|
||||
FileBrowser.SetDefaultFilter(".e0gr");
|
||||
yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
yield return FileBrowser
|
||||
.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
|
||||
if (FileBrowser.Success)
|
||||
{
|
||||
if (FileBrowser.Success) {
|
||||
var path = FileBrowser.Result[0];
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
PlayerPrefs.SetString("gameRequestLocation", dirPath);
|
||||
@@ -496,16 +442,15 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ShowLoadCustomMapCoroutine()
|
||||
{
|
||||
IEnumerator ShowLoadCustomMapCoroutine() {
|
||||
var initialPath = PlayerPrefs.GetString("mapLocation", null);
|
||||
|
||||
FileBrowser.SetFilters(true, new FileBrowser.Filter("Maps", ".e0mj"));
|
||||
FileBrowser.SetDefaultFilter(".e0mj");
|
||||
yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
yield return FileBrowser
|
||||
.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
|
||||
if (FileBrowser.Success)
|
||||
{
|
||||
if (FileBrowser.Success) {
|
||||
var path = FileBrowser.Result[0];
|
||||
|
||||
var mapJson = File.ReadAllText(path);
|
||||
@@ -514,16 +459,13 @@ public class CustomBattleHandler : MonoBehaviour
|
||||
var map = jp.Parse<HexMap>(mapJson);
|
||||
|
||||
Google.Protobuf.ByteString bs = null;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
using (var stream = new MemoryStream()) {
|
||||
map.WriteTo(stream);
|
||||
bs = Google.Protobuf.ByteString.CopyFrom(stream.ToArray());
|
||||
}
|
||||
|
||||
SetUpMap(map, "Custom", bs);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
customMapToggle.isOn = false;
|
||||
CustomMapToggleClicked();
|
||||
}
|
||||
|
||||
+8
-13
@@ -4,8 +4,7 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
public class RunningGameItem : MonoBehaviour
|
||||
{
|
||||
public class RunningGameItem : MonoBehaviour {
|
||||
public GameObject item;
|
||||
public TextMeshProUGUI gameIdField;
|
||||
public TextMeshProUGUI leaderField;
|
||||
@@ -16,21 +15,17 @@ public class RunningGameItem : MonoBehaviour
|
||||
private long gameId;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
void Start() {}
|
||||
|
||||
}
|
||||
public void GoClicked() { GoCallback(gameId); }
|
||||
|
||||
public void GoClicked()
|
||||
{
|
||||
GoCallback(gameId);
|
||||
}
|
||||
|
||||
public void SetRunningGame(long gameId, AvailableLeader leader)
|
||||
{
|
||||
public void SetRunningGame(long gameId, AvailableLeader leader) {
|
||||
this.gameId = gameId;
|
||||
|
||||
gameIdField.text = string.Format("{0:X}", gameId);
|
||||
leaderField.text = string.Format("{0} ({1})", leader.Name, eagle.DisplayNames.ProfessionNames[leader.Profession]);
|
||||
leaderField.text = string.Format(
|
||||
"{0} ({1})",
|
||||
leader.Name,
|
||||
eagle.DisplayNames.ProfessionNames[leader.Profession]);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-9
@@ -2,24 +2,22 @@
|
||||
using TMPro;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
public class WaitingGameItem : MonoBehaviour
|
||||
{
|
||||
public class WaitingGameItem : MonoBehaviour {
|
||||
public GameObject item;
|
||||
public TextMeshProUGUI gameIdField;
|
||||
public TextMeshProUGUI leaderField;
|
||||
public TextMeshProUGUI playerCountField;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
void Start() {}
|
||||
|
||||
}
|
||||
|
||||
public void SetWaitingGame(long gameId, string playersString, AvailableLeader leader)
|
||||
{
|
||||
public void SetWaitingGame(long gameId, string playersString, AvailableLeader leader) {
|
||||
gameIdField.text = string.Format("{0:X}", gameId);
|
||||
playerCountField.text = playersString;
|
||||
|
||||
leaderField.text = string.Format("{0} ({1})", leader.Name, eagle.DisplayNames.ProfessionNames[leader.Profession]);
|
||||
leaderField.text = string.Format(
|
||||
"{0} ({1})",
|
||||
leader.Name,
|
||||
eagle.DisplayNames.ProfessionNames[leader.Profession]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,36 +3,29 @@ using Grpc.Core;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConnectionKiller : MonoBehaviour
|
||||
{
|
||||
private static CancellationTokenSource EagleGlobalShutdownTokenSource = new CancellationTokenSource();
|
||||
private static CancellationTokenSource ShardokGlobalShutdownTokenSource = new CancellationTokenSource();
|
||||
public class ConnectionKiller : MonoBehaviour {
|
||||
private static CancellationTokenSource EagleGlobalShutdownTokenSource =
|
||||
new CancellationTokenSource();
|
||||
private static CancellationTokenSource ShardokGlobalShutdownTokenSource =
|
||||
new CancellationTokenSource();
|
||||
public static CancellationToken EagleCancellationToken => EagleGlobalShutdownTokenSource.Token;
|
||||
public static CancellationToken ShardokCancellationToken => ShardokGlobalShutdownTokenSource.Token;
|
||||
public static CancellationToken ShardokCancellationToken =>
|
||||
ShardokGlobalShutdownTokenSource.Token;
|
||||
|
||||
public void OnApplicationQuit()
|
||||
{
|
||||
ShutdownAll();
|
||||
}
|
||||
public void OnApplicationQuit() { ShutdownAll(); }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingPlayMode)
|
||||
{
|
||||
ShutdownAll();
|
||||
}
|
||||
void OnPlayModeStateChanged(PlayModeStateChange state) {
|
||||
if (state == PlayModeStateChange.ExitingPlayMode) { ShutdownAll(); }
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void ShutdownShardok()
|
||||
{
|
||||
public static void ShutdownShardok() {
|
||||
ShardokGlobalShutdownTokenSource.Cancel();
|
||||
ShardokGlobalShutdownTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
private static void ShutdownAll()
|
||||
{
|
||||
private static void ShutdownAll() {
|
||||
System.Console.Out.WriteLine("Attempting GRPC shutdown.");
|
||||
EagleGlobalShutdownTokenSource.Cancel();
|
||||
ShardokGlobalShutdownTokenSource.Cancel();
|
||||
|
||||
@@ -3,30 +3,20 @@ using System.Collections.Generic;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public static class BattalionUtils
|
||||
{
|
||||
public static readonly IComparer<BattalionView> BattalionComparer = new _BattalionComparer();
|
||||
namespace eagle {
|
||||
public static class BattalionUtils {
|
||||
public static readonly IComparer<BattalionView> BattalionComparer =
|
||||
new _BattalionComparer();
|
||||
|
||||
private class _BattalionComparer : Comparer<BattalionView>
|
||||
{
|
||||
public override int Compare(BattalionView x, BattalionView y)
|
||||
{
|
||||
if (x.Type.CompareTo(y.Type) != 0)
|
||||
{
|
||||
private class _BattalionComparer : Comparer<BattalionView> {
|
||||
public override int Compare(BattalionView x, BattalionView y) {
|
||||
if (x.Type.CompareTo(y.Type) != 0) {
|
||||
return x.Type.CompareTo(y.Type);
|
||||
}
|
||||
else if (x.Size.CompareTo(y.Size) != 0)
|
||||
{
|
||||
} else if (x.Size.CompareTo(y.Size) != 0) {
|
||||
return -x.Size.CompareTo(y.Size);
|
||||
}
|
||||
else if ((x.Training + x.Armament).CompareTo(y.Training + y.Armament) != 0)
|
||||
{
|
||||
} else if ((x.Training + x.Armament).CompareTo(y.Training + y.Armament) != 0) {
|
||||
return -(x.Training + x.Armament).CompareTo(y.Training + y.Armament);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-14
@@ -1,23 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CommandButtonController : MonoBehaviour
|
||||
{
|
||||
public class CommandButtonController : MonoBehaviour {
|
||||
public Button buttonPrefab;
|
||||
public eagle.EagleGameController gameController;
|
||||
|
||||
void Start()
|
||||
{
|
||||
ClearButtonContents();
|
||||
}
|
||||
void Start() { ClearButtonContents(); }
|
||||
|
||||
public void SetButtonContents(GUIContent[] contents)
|
||||
{
|
||||
public void SetButtonContents(GUIContent[] contents) {
|
||||
ClearButtonContents();
|
||||
|
||||
int contentsCount = contents.Length;
|
||||
for (int i = 0; i < contentsCount; i++)
|
||||
{
|
||||
for (int i = 0; i < contentsCount; i++) {
|
||||
int buttonIndex = i;
|
||||
var newButton = Instantiate(buttonPrefab, gameObject.transform);
|
||||
newButton.GetComponentInChildren<RawImage>().texture = contents[i].image;
|
||||
@@ -25,11 +19,9 @@ public class CommandButtonController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearButtonContents()
|
||||
{
|
||||
public void ClearButtonContents() {
|
||||
int childCount = gameObject.transform.childCount;
|
||||
for (int i = childCount - 1; i >= 0; i--)
|
||||
{
|
||||
for (int i = childCount - 1; i >= 0; i--) {
|
||||
GameObject.Destroy(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
+53
-93
@@ -6,29 +6,27 @@ using TMPro;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using CommandType = AvailableCommand.SealedValueOneofCase;
|
||||
|
||||
public class CommandPanelController : MonoBehaviour
|
||||
{
|
||||
public class CommandPanelController : MonoBehaviour {
|
||||
public EagleGameController mainController;
|
||||
|
||||
public CommandSelector _selector;
|
||||
public CommandSelector Selector
|
||||
{
|
||||
public CommandSelector Selector {
|
||||
get => _selector;
|
||||
private set
|
||||
{
|
||||
if (_selector != value)
|
||||
{
|
||||
private
|
||||
set {
|
||||
if (_selector != value) {
|
||||
if (_selector != null) _selector.Hide();
|
||||
_selector = value;
|
||||
if (_selector != null) _selector.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
public SelectedCommand SelectedCommand { get { return Selector == null ? null : Selector.Command; } }
|
||||
public SelectedCommand SelectedCommand {
|
||||
get { return Selector == null ? null : Selector.Command; }
|
||||
}
|
||||
|
||||
public TMP_Text headerLabel;
|
||||
public Button commitCommandButton;
|
||||
@@ -39,27 +37,20 @@ namespace eagle
|
||||
public CommandWarningPanelController commandWarningPanelController;
|
||||
|
||||
private AvailableCommand _availableCommand;
|
||||
public AvailableCommand AvailableCommand
|
||||
{
|
||||
public AvailableCommand AvailableCommand {
|
||||
get => _availableCommand;
|
||||
private set
|
||||
{
|
||||
if (_availableCommand != value)
|
||||
{
|
||||
_availableCommand = value;
|
||||
}
|
||||
private
|
||||
set {
|
||||
if (_availableCommand != value) { _availableCommand = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAvailableCommandAndSelector(AvailableCommand cmd, CommandSelector sel)
|
||||
{
|
||||
public void SetAvailableCommandAndSelector(AvailableCommand cmd, CommandSelector sel) {
|
||||
AvailableCommand = cmd;
|
||||
Selector = sel;
|
||||
|
||||
try
|
||||
{
|
||||
if (AvailableCommand == null)
|
||||
{
|
||||
try {
|
||||
if (AvailableCommand == null) {
|
||||
Selector = null;
|
||||
headerLabel.text = null;
|
||||
return;
|
||||
@@ -67,18 +58,13 @@ namespace eagle
|
||||
|
||||
Selector.UpdateAvailableCommand(Model, AvailableCommand);
|
||||
headerLabel.text = Selector.HeaderString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorPanel.Add(e);
|
||||
}
|
||||
} catch (Exception e) { errorPanel.Add(e); }
|
||||
}
|
||||
|
||||
public List<CommandSelector> AppropriateSelectors(AvailableCommand cmd) =>
|
||||
commandSelectors.FindAll(sel => sel.IsAppropriateFor(cmd));
|
||||
|
||||
public List<GUIContent> ButtonContentsForCommand(AvailableCommand cmd)
|
||||
{
|
||||
public List<GUIContent> ButtonContentsForCommand(AvailableCommand cmd) {
|
||||
return (from sel in AppropriateSelectors(cmd)
|
||||
where sel.ButtonImage != null
|
||||
select new GUIContent(sel.ButtonImage, sel.HeaderString)).ToList();
|
||||
@@ -86,97 +72,71 @@ namespace eagle
|
||||
|
||||
private List<CommandSelector> commandSelectors;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
public void Awake() {
|
||||
commandSelectors = new List<CommandSelector>();
|
||||
|
||||
foreach (Transform child in gameObject.transform)
|
||||
{
|
||||
foreach (Transform child in gameObject.transform) {
|
||||
var sel = child.gameObject.GetComponent<CommandSelector>();
|
||||
if (sel != null)
|
||||
{
|
||||
commandSelectors.Add(sel);
|
||||
}
|
||||
if (sel != null) { commandSelectors.Add(sel); }
|
||||
}
|
||||
|
||||
foreach (var kvp in commandSelectors)
|
||||
{
|
||||
foreach (var kvp in commandSelectors) {
|
||||
kvp.SetFocusInfoPanelController(focusPanel);
|
||||
kvp.gameObject.SetActive(true);
|
||||
kvp.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
foreach (var kvp in commandSelectors)
|
||||
{
|
||||
kvp.gameObject.SetActive(false);
|
||||
}
|
||||
public void Start() {
|
||||
foreach (var kvp in commandSelectors) { kvp.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void PointerEnteredCommitButton()
|
||||
{
|
||||
if (Selector != null)
|
||||
{
|
||||
if (!Selector.EnableCommitButton)
|
||||
{
|
||||
if (Selector.DisabledCommitButtonReason == null || Selector.DisabledCommitButtonReason == "")
|
||||
{
|
||||
commandWarningPanelController.SetWarning("Invalid", "CROSBY NEEDS TO PUT SOME TEXT HERE");
|
||||
public void PointerEnteredCommitButton() {
|
||||
if (Selector != null) {
|
||||
if (!Selector.EnableCommitButton) {
|
||||
if (Selector.DisabledCommitButtonReason == null ||
|
||||
Selector.DisabledCommitButtonReason == "") {
|
||||
commandWarningPanelController.SetWarning(
|
||||
"Invalid",
|
||||
"CROSBY NEEDS TO PUT SOME TEXT HERE");
|
||||
} else {
|
||||
commandWarningPanelController.SetWarning(
|
||||
"Invalid",
|
||||
Selector.DisabledCommitButtonReason);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandWarningPanelController.SetWarning("Invalid", Selector.DisabledCommitButtonReason);
|
||||
}
|
||||
}
|
||||
else if (Selector.WarnOnCommitButton)
|
||||
{
|
||||
commandWarningPanelController.SetWarning("Are you sure?", Selector.CommitWarningText);
|
||||
} else if (Selector.WarnOnCommitButton) {
|
||||
commandWarningPanelController.SetWarning(
|
||||
"Are you sure?",
|
||||
Selector.CommitWarningText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PointerExitedCommitButton()
|
||||
{
|
||||
commandWarningPanelController.ClearWarning();
|
||||
}
|
||||
public void PointerExitedCommitButton() { commandWarningPanelController.ClearWarning(); }
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
public void OnGUI() {
|
||||
var eventType = Event.current.type;
|
||||
try
|
||||
{
|
||||
if (Selector == null)
|
||||
{
|
||||
try {
|
||||
if (Selector == null) {
|
||||
commitCommandButton.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
bool disableWarningPanel = !commitCommandButton.gameObject.activeSelf;
|
||||
|
||||
if (Selector.WarnOnCommitButton)
|
||||
{
|
||||
commitButtonText.text = $"<color=#FF0000FF>{Selector.CommitButtonString}</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Selector.WarnOnCommitButton) {
|
||||
commitButtonText.text =
|
||||
$"<color=#FF0000FF>{Selector.CommitButtonString}</color>";
|
||||
} else {
|
||||
commitButtonText.text = Selector.CommitButtonString;
|
||||
}
|
||||
commitCommandButton.gameObject.SetActive(true);
|
||||
commitCommandButton.interactable = Selector.EnableCommitButton;
|
||||
|
||||
if (disableWarningPanel)
|
||||
{
|
||||
MainQueue.Q.EnqueueForNextUpdate(() =>
|
||||
{
|
||||
commandWarningPanelController.ClearWarning();
|
||||
});
|
||||
if (disableWarningPanel) {
|
||||
MainQueue.Q.EnqueueForNextUpdate(
|
||||
() => { commandWarningPanelController.ClearWarning(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
Debug.Log($"Event type is {eventType}");
|
||||
errorPanel.Add(e);
|
||||
}
|
||||
|
||||
+16
-20
@@ -5,13 +5,11 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class AlmsCommandSelector : CommandSelector
|
||||
{
|
||||
public class AlmsCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public Slider foodSlider;
|
||||
public TMP_Text foodGivenLabel;
|
||||
@@ -24,7 +22,8 @@ namespace eagle
|
||||
|
||||
private int SelectedFoodAmount => (int)foodSlider.value;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.AlmsCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.AlmsCommand;
|
||||
public override string HeaderString => "Give Alms";
|
||||
public override string CommitButtonString => "Commit Alms";
|
||||
|
||||
@@ -32,35 +31,32 @@ namespace eagle
|
||||
public override string DisabledCommitButtonReason => "Must include some food";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => AlmsCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
AlmsCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = AlmsCommand.AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
AlmsCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid]).ToList();
|
||||
|
||||
foodSlider.maxValue = AvailableFoodAmount;
|
||||
foodSlider.value = 0;
|
||||
foodGivenLabel.text = "0";
|
||||
}
|
||||
|
||||
public void SelectedProvinceChanged(int newValue)
|
||||
{
|
||||
public void SelectedProvinceChanged(int newValue) {
|
||||
foodSlider.value = Math.Min(foodSlider.value, AvailableFoodAmount);
|
||||
foodSlider.maxValue = AvailableFoodAmount;
|
||||
}
|
||||
|
||||
public void FoodSliderChanged(float newValue)
|
||||
{
|
||||
public void FoodSliderChanged(float newValue) {
|
||||
foodGivenLabel.text = ((int)newValue).ToString();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
AlmsCommand = new AlmsSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
AlmsCommand =
|
||||
new AlmsSelectedCommand {
|
||||
Amount = SelectedFoodAmount,
|
||||
ActingHeroId = SelectedHeroId
|
||||
}
|
||||
|
||||
+37
-35
@@ -5,20 +5,22 @@ using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using BattalionId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
using FactionId = Int32;
|
||||
|
||||
public class ApprehendOutlawCommandSelector : CommandSelector
|
||||
{
|
||||
public class ApprehendOutlawCommandSelector : CommandSelector {
|
||||
private HeroId SelectedHeroId => actingHeroDropdownController.SelectedHeroId;
|
||||
private BattalionId? SelectedBattalionId => actingBattalionDropdown.value == 0 ? null : (BattalionId?)AvailableBattalions[actingBattalionDropdown.value - 1].Id;
|
||||
private BattalionId? SelectedBattalionId =>
|
||||
actingBattalionDropdown.value == 0
|
||||
? null
|
||||
: (BattalionId?)AvailableBattalions[actingBattalionDropdown.value - 1].Id;
|
||||
private HeroId TargetedHeroId => AvailableTargetHeroIds[targetOutlawDropdown.value];
|
||||
|
||||
private ApprehendOutlawAvailableCommand ApprehendOutlawCommand => _availableCommand.ApprehendOutlawCommand;
|
||||
private ApprehendOutlawAvailableCommand ApprehendOutlawCommand =>
|
||||
_availableCommand.ApprehendOutlawCommand;
|
||||
private ProvinceId ActingProvinceId => ApprehendOutlawCommand.ActingProvinceId;
|
||||
|
||||
public HeroDropdownController actingHeroDropdownController;
|
||||
@@ -27,12 +29,15 @@ namespace eagle
|
||||
|
||||
public EagleCommonTextures textures;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ApprehendOutlawCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ApprehendOutlawCommand;
|
||||
public override string HeaderString => "Apprehend Outlaw";
|
||||
public override string CommitButtonString => "Commit Apprehend Outlaw";
|
||||
|
||||
public override bool HeroIsTargetable(HeroId heroId) => ApprehendOutlawCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => actingHeroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
ApprehendOutlawCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
actingHeroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private List<HeroId> AvailableTargetHeroIds { get; set; }
|
||||
private ProvinceView Province => _model.Provinces[ActingProvinceId];
|
||||
@@ -42,57 +47,54 @@ namespace eagle
|
||||
.OrderBy(batt => batt.Type)
|
||||
.ToList();
|
||||
|
||||
private string outlawDropdownString(ResidentOutlaw outlaw)
|
||||
{
|
||||
private string outlawDropdownString(ResidentOutlaw outlaw) {
|
||||
string lastFactionString = "";
|
||||
|
||||
if (outlaw.LastFactionId is FactionId fid)
|
||||
{
|
||||
if (outlaw.LastFactionId is FactionId fid) {
|
||||
lastFactionString = $" ({_model.FactionName(fid)})";
|
||||
}
|
||||
return $"{outlaw.Hero.Name}{lastFactionString}";
|
||||
}
|
||||
|
||||
private TMP_Dropdown.OptionData BattalionOption(BattalionView bv)
|
||||
{
|
||||
private TMP_Dropdown.OptionData BattalionOption(BattalionView bv) {
|
||||
var texture = textures.BattalionType(bv.Type);
|
||||
return new TMP_Dropdown.OptionData
|
||||
{
|
||||
image = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)),
|
||||
return new TMP_Dropdown.OptionData {
|
||||
image = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f)),
|
||||
text = bv.Size.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
actingHeroDropdownController.AvailableHeroes = ApprehendOutlawCommand.AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
protected override void SetUpUI() {
|
||||
actingHeroDropdownController.AvailableHeroes =
|
||||
ApprehendOutlawCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
|
||||
AvailableTargetHeroIds = ApprehendOutlawCommand
|
||||
.Outlaws
|
||||
.Select(uh => uh.Hero.Id)
|
||||
.ToList();
|
||||
AvailableTargetHeroIds =
|
||||
ApprehendOutlawCommand.Outlaws.Select(uh => uh.Hero.Id).ToList();
|
||||
|
||||
actingBattalionDropdown.ClearOptions();
|
||||
actingBattalionDropdown.AddOptions(new List<TMP_Dropdown.OptionData> { new TMP_Dropdown.OptionData { text = "No Battalion" } });
|
||||
actingBattalionDropdown.AddOptions(AvailableBattalions.Select(BattalionOption).ToList());
|
||||
actingBattalionDropdown.AddOptions(new List<TMP_Dropdown.OptionData> {
|
||||
new TMP_Dropdown.OptionData { text = "No Battalion" }
|
||||
});
|
||||
actingBattalionDropdown.AddOptions(
|
||||
AvailableBattalions.Select(BattalionOption).ToList());
|
||||
actingBattalionDropdown.value = Math.Min(1, AvailableBattalions.Count);
|
||||
|
||||
targetOutlawDropdown.ClearOptions();
|
||||
var outlawNames = ApprehendOutlawCommand
|
||||
.Outlaws
|
||||
.Select(opt => outlawDropdownString(opt))
|
||||
var outlawNames =
|
||||
ApprehendOutlawCommand.Outlaws.Select(opt => outlawDropdownString(opt))
|
||||
.ToList();
|
||||
|
||||
targetOutlawDropdown.AddOptions(outlawNames);
|
||||
targetOutlawDropdown.value = 0;
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ApprehendOutlawSelectedCommand = new ApprehendOutlawSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ApprehendOutlawSelectedCommand =
|
||||
new ApprehendOutlawSelectedCommand {
|
||||
HeroIdToApprehend = TargetedHeroId,
|
||||
BattalionId = SelectedBattalionId,
|
||||
ActingHeroId = SelectedHeroId
|
||||
|
||||
+32
-59
@@ -8,12 +8,10 @@ using TMPro;
|
||||
using common;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class ArmTroopsCommandSelector : CommandSelector
|
||||
{
|
||||
public class ArmTroopsCommandSelector : CommandSelector {
|
||||
List<double> costs;
|
||||
List<int> newArmaments;
|
||||
List<BattalionView> battalions;
|
||||
@@ -26,23 +24,24 @@ namespace eagle
|
||||
public TMP_Text availableText;
|
||||
public TMP_Text maxLabel;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ArmTroopsCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ArmTroopsCommand;
|
||||
|
||||
private ArmTroopsAvailableCommand ArmTroopsAvailableCommand => _availableCommand.ArmTroopsCommand;
|
||||
private ArmTroopsAvailableCommand ArmTroopsAvailableCommand =>
|
||||
_availableCommand.ArmTroopsCommand;
|
||||
private ProvinceId ActingProvinceId => ArmTroopsAvailableCommand.ActingProvinceId;
|
||||
|
||||
override protected void SetUpUI()
|
||||
{
|
||||
override protected void SetUpUI() {
|
||||
var province = _model.Provinces[ActingProvinceId];
|
||||
battalions = ArmTroopsAvailableCommand.AvailableBattalions
|
||||
battalions =
|
||||
ArmTroopsAvailableCommand.AvailableBattalions
|
||||
.Select(bid => province.FullInfo.Battalions.First(b => b.Id == bid))
|
||||
.OrderBy(b => b, BattalionUtils.BattalionComparer)
|
||||
.ToList();
|
||||
newArmaments = battalions.Select(b => (int)b.Armament).ToList();
|
||||
|
||||
var costDict = new Dictionary<BattalionTypeId, double>();
|
||||
foreach (var t in ArmTroopsAvailableCommand.ArmamentCosts)
|
||||
{
|
||||
foreach (var t in ArmTroopsAvailableCommand.ArmamentCosts) {
|
||||
costDict[t.Type] = t.Cost;
|
||||
}
|
||||
|
||||
@@ -66,8 +65,7 @@ namespace eagle
|
||||
private string _disabledCommitButtonReason;
|
||||
public override string DisabledCommitButtonReason => _disabledCommitButtonReason;
|
||||
|
||||
private void PopulateRow(int index)
|
||||
{
|
||||
private void PopulateRow(int index) {
|
||||
var row = armTroopsTable.ComponentAt<ArmTroopsRowController>(index);
|
||||
var battalion = battalions[index];
|
||||
row.BattalionImage = textures.BattalionType(battalion.Type);
|
||||
@@ -82,8 +80,7 @@ namespace eagle
|
||||
SetValuesAndButtons(index);
|
||||
}
|
||||
|
||||
private void SetValuesAndButtons(int index)
|
||||
{
|
||||
private void SetValuesAndButtons(int index) {
|
||||
var row = armTroopsTable.ComponentAt<ArmTroopsRowController>(index);
|
||||
var battalion = battalions[index];
|
||||
var newArmament = newArmaments[index];
|
||||
@@ -100,86 +97,67 @@ namespace eagle
|
||||
UpdateCost();
|
||||
}
|
||||
|
||||
private void UpdateCost()
|
||||
{
|
||||
private void UpdateCost() {
|
||||
_enableCommit = true;
|
||||
totalCostText.color = Color.black;
|
||||
int cost = Cost();
|
||||
|
||||
totalCostText.text = cost.ToString();
|
||||
if (cost > availableGold)
|
||||
{
|
||||
if (cost > availableGold) {
|
||||
totalCostText.color = Color.red;
|
||||
_enableCommit = false;
|
||||
_disabledCommitButtonReason = "Not enough gold";
|
||||
}
|
||||
if (cost == 0)
|
||||
{
|
||||
if (cost == 0) {
|
||||
_enableCommit = false;
|
||||
_disabledCommitButtonReason = "No battalions have changed";
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTableAndCost()
|
||||
{
|
||||
private void UpdateTableAndCost() {
|
||||
armTroopsTable.RowCount = battalions.Count;
|
||||
|
||||
for (int i = 0; i < battalions.Count; i++)
|
||||
{
|
||||
PopulateRow(i);
|
||||
}
|
||||
for (int i = 0; i < battalions.Count; i++) { PopulateRow(i); }
|
||||
|
||||
UpdateCost();
|
||||
}
|
||||
|
||||
public void PlusClicked(int index)
|
||||
{
|
||||
public void PlusClicked(int index) {
|
||||
newArmaments[index] = Math.Min(maxArmament, newArmaments[index] + 1);
|
||||
SetValuesAndButtons(index);
|
||||
}
|
||||
|
||||
|
||||
public void MinusClicked(int index)
|
||||
{
|
||||
newArmaments[index] = Math.Max((int)battalions[index].Armament, newArmaments[index] - 1);
|
||||
public void MinusClicked(int index) {
|
||||
newArmaments[index] =
|
||||
Math.Max((int)battalions[index].Armament, newArmaments[index] - 1);
|
||||
SetValuesAndButtons(index);
|
||||
}
|
||||
|
||||
|
||||
public void ResetClicked(int index)
|
||||
{
|
||||
public void ResetClicked(int index) {
|
||||
newArmaments[index] = (int)battalions[index].Armament;
|
||||
SetValuesAndButtons(index);
|
||||
}
|
||||
|
||||
|
||||
public void MaxClicked(int index)
|
||||
{
|
||||
public void MaxClicked(int index) {
|
||||
newArmaments[index] = maxArmament;
|
||||
SetValuesAndButtons(index);
|
||||
}
|
||||
|
||||
public void MaxAllClicked()
|
||||
{
|
||||
public void MaxAllClicked() {
|
||||
newArmaments = battalions.Select(b => maxArmament).ToList();
|
||||
UpdateTableAndCost();
|
||||
}
|
||||
|
||||
public void ResetAllClicked()
|
||||
{
|
||||
public void ResetAllClicked() {
|
||||
newArmaments = battalions.Select(b => (int)b.Armament).ToList();
|
||||
UpdateTableAndCost();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var atc = new ArmTroopsSelectedCommand();
|
||||
for (int i = 0; i < newArmaments.Count; i++)
|
||||
{
|
||||
if (newArmaments[i] > battalions[i].Armament)
|
||||
{
|
||||
for (int i = 0; i < newArmaments.Count; i++) {
|
||||
if (newArmaments[i] > battalions[i].Armament) {
|
||||
var ab = new ArmedBattalion();
|
||||
ab.Id = battalions[i].Id;
|
||||
ab.NewArmament = (int)newArmaments[i];
|
||||
@@ -187,21 +165,16 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
ArmTroopsCommand = atc
|
||||
};
|
||||
var cmd = new SelectedCommand { ArmTroopsCommand = atc };
|
||||
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
private int Cost()
|
||||
{
|
||||
private int Cost() {
|
||||
double totalCost = 0.0;
|
||||
|
||||
for (int i = 0; i < newArmaments.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < newArmaments.Count; i++) {
|
||||
var battalion = battalions[i];
|
||||
|
||||
totalCost += costs[i] * Math.Max(newArmaments[i] - battalion.Armament, 0.0);
|
||||
|
||||
+38
-41
@@ -7,27 +7,29 @@ using TMPro;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class AttackDecisionCommandSelector : CommandSelector
|
||||
{
|
||||
public class AttackDecisionCommandSelector : CommandSelector {
|
||||
public EventBasedTable unitsTable;
|
||||
public EventBasedTable armiesTable;
|
||||
|
||||
private static Dictionary<AttackDecisionType, string> commitStrings = new Dictionary<AttackDecisionType, string>
|
||||
{
|
||||
private static Dictionary<AttackDecisionType, string> commitStrings =
|
||||
new Dictionary<AttackDecisionType, string> {
|
||||
{ AttackDecisionType.AdvanceDecision, "Commit Advance" },
|
||||
{ AttackDecisionType.DemandTributeDecision, "Commit Demand Tribute" },
|
||||
{ AttackDecisionType.WithdrawDecision, "Commit Withdraw" },
|
||||
};
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.AttackDecisionCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.AttackDecisionCommand;
|
||||
public override string HeaderString => "Attack Decision";
|
||||
public override string CommitButtonString => commitStrings[SelectedDecision];
|
||||
public override bool EnableCommitButton => SelectedDecision != AttackDecisionType.DemandTributeDecision || FoodDemanded > 0 || GoldDemanded > 0;
|
||||
public override string DisabledCommitButtonReason => "Must select some food or gold for tribute";
|
||||
public override bool EnableCommitButton =>
|
||||
SelectedDecision != AttackDecisionType.DemandTributeDecision || FoodDemanded > 0 ||
|
||||
GoldDemanded > 0;
|
||||
public override string DisabledCommitButtonReason =>
|
||||
"Must select some food or gold for tribute";
|
||||
|
||||
public Toggle AdvanceToggle;
|
||||
public Toggle DemandTributeToggle;
|
||||
@@ -44,49 +46,48 @@ namespace eagle
|
||||
public TMP_Text GoldLabel;
|
||||
public TMP_Text FoodLabel;
|
||||
|
||||
private AttackDecisionAvailableCommand AttackDecisionCommand => _availableCommand.AttackDecisionCommand;
|
||||
private AttackDecisionAvailableCommand AttackDecisionCommand =>
|
||||
_availableCommand.AttackDecisionCommand;
|
||||
private ProvinceId ActingProvinceId => AttackDecisionCommand.ActingProvinceId;
|
||||
|
||||
private AttackDecisionType SelectedDecision =>
|
||||
(AdvanceToggle.isOn) ? AttackDecisionType.AdvanceDecision :
|
||||
(DemandTributeToggle.isOn) ? AttackDecisionType.DemandTributeDecision :
|
||||
AttackDecisionType.WithdrawDecision;
|
||||
(AdvanceToggle.isOn) ? AttackDecisionType.AdvanceDecision
|
||||
: (DemandTributeToggle.isOn) ? AttackDecisionType.DemandTributeDecision
|
||||
: AttackDecisionType.WithdrawDecision;
|
||||
|
||||
private int FoodDemanded => (int)FoodSlider.value;
|
||||
private int GoldDemanded => (int)GoldSlider.value;
|
||||
|
||||
private TributeAmount Tribute => DemandTributeToggle.isOn ? new TributeAmount { Food = FoodDemanded, Gold = GoldDemanded } : null;
|
||||
private TributeAmount Tribute =>
|
||||
DemandTributeToggle.isOn
|
||||
? new TributeAmount { Food = FoodDemanded, Gold = GoldDemanded }
|
||||
: null;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
AttackDecisionCommand = new AttackDecisionSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
AttackDecisionCommand =
|
||||
new AttackDecisionSelectedCommand {
|
||||
Decision = SelectedDecision,
|
||||
Tribute = Tribute
|
||||
}
|
||||
};
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
unitsTable.RowCount = AttackDecisionCommand.ActingUnits.Count;
|
||||
ProvinceView province = _model.Provinces[ActingProvinceId];
|
||||
|
||||
AttackDecisionCommand.ActingUnits.Each((cu, idx) =>
|
||||
{
|
||||
AttackDecisionCommand.ActingUnits.Each((cu, idx) => {
|
||||
CombatUnitRowController row = unitsTable.ComponentAt<CombatUnitRowController>(idx);
|
||||
row.Hero = cu.Hero;
|
||||
row.Battalion = cu.Battalion;
|
||||
});
|
||||
|
||||
armiesTable.RowCount = AttackDecisionCommand.Armies.Count;
|
||||
AttackDecisionCommand.Armies.Each((army, idx) =>
|
||||
{
|
||||
AttackDecisionCommand.Armies.Each((army, idx) => {
|
||||
IncomingArmyTableRow row = armiesTable.ComponentAt<IncomingArmyTableRow>(idx);
|
||||
row.Faction = _model.FactionName(army.FactionId);
|
||||
row.HeroCount = army.HeroCount;
|
||||
row.TroopCount = army.TroopCount;
|
||||
switch (army.Hostility)
|
||||
{
|
||||
switch (army.Hostility) {
|
||||
case Net.Eagle0.Common.Hostility.AlliedHostility:
|
||||
row.TextColor = Color.green;
|
||||
break;
|
||||
@@ -100,17 +101,20 @@ namespace eagle
|
||||
row.Origin = _model.Provinces[army.OriginProvinceId].Name;
|
||||
});
|
||||
|
||||
var enableAttack = AttackDecisionCommand.AvailableDecisions.Contains(AttackDecisionType.AdvanceDecision);
|
||||
var enableAttack = AttackDecisionCommand.AvailableDecisions.Contains(
|
||||
AttackDecisionType.AdvanceDecision);
|
||||
AdvanceToggle.enabled = enableAttack;
|
||||
AdvanceToggle.gameObject.SetActive(enableAttack);
|
||||
AdvanceImage.SetActive(enableAttack);
|
||||
|
||||
var enableWithdraw = AttackDecisionCommand.AvailableDecisions.Contains(AttackDecisionType.WithdrawDecision);
|
||||
var enableWithdraw = AttackDecisionCommand.AvailableDecisions.Contains(
|
||||
AttackDecisionType.WithdrawDecision);
|
||||
WithdrawToggle.enabled = enableWithdraw;
|
||||
WithdrawToggle.gameObject.SetActive(enableWithdraw);
|
||||
WithdrawImage.SetActive(enableWithdraw);
|
||||
|
||||
var enableDemandTribute = AttackDecisionCommand.AvailableDecisions.Contains(AttackDecisionType.DemandTributeDecision);
|
||||
var enableDemandTribute = AttackDecisionCommand.AvailableDecisions.Contains(
|
||||
AttackDecisionType.DemandTributeDecision);
|
||||
DemandTributeToggle.enabled = enableDemandTribute;
|
||||
DemandTributeToggle.gameObject.SetActive(enableDemandTribute);
|
||||
DemandTributeImage.SetActive(enableDemandTribute);
|
||||
@@ -133,18 +137,15 @@ namespace eagle
|
||||
EnableSliders(false);
|
||||
}
|
||||
|
||||
public void GoldSliderChanged(float newValue)
|
||||
{
|
||||
public void GoldSliderChanged(float newValue) {
|
||||
GoldLabel.text = ((int)newValue).ToString();
|
||||
}
|
||||
|
||||
public void FoodSliderChanged(float newValue)
|
||||
{
|
||||
public void FoodSliderChanged(float newValue) {
|
||||
FoodLabel.text = ((int)newValue).ToString();
|
||||
}
|
||||
|
||||
private void EnableSliders(bool enabled)
|
||||
{
|
||||
private void EnableSliders(bool enabled) {
|
||||
GoldIcon.gameObject.SetActive(enabled);
|
||||
FoodIcon.gameObject.SetActive(enabled);
|
||||
GoldSlider.gameObject.SetActive(enabled);
|
||||
@@ -153,17 +154,13 @@ namespace eagle
|
||||
FoodLabel.gameObject.SetActive(enabled);
|
||||
}
|
||||
|
||||
public void ToggleChanged(bool value)
|
||||
{
|
||||
public void ToggleChanged(bool value) {
|
||||
bool enableSliders = (SelectedDecision == AttackDecisionType.DemandTributeDecision);
|
||||
|
||||
EnableSliders(enableSliders);
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-38
@@ -3,60 +3,52 @@ using System.Collections.Generic;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
using HeroId = Int32;
|
||||
using BattalionId = Int32;
|
||||
using FactionId = Int32;
|
||||
|
||||
public abstract class CommandSelector : MonoBehaviour
|
||||
{
|
||||
public abstract class CommandSelector : MonoBehaviour {
|
||||
public Texture ButtonImage;
|
||||
|
||||
public abstract AvailableCommand.SealedValueOneofCase CommandType { get; }
|
||||
public virtual bool IsAppropriateFor(AvailableCommand cmd) => cmd.SealedValueCase == CommandType;
|
||||
public virtual bool IsAppropriateFor(AvailableCommand cmd) => cmd.SealedValueCase
|
||||
== CommandType;
|
||||
public abstract string HeaderString { get; }
|
||||
public abstract string CommitButtonString { get; }
|
||||
public abstract SelectedCommand Command { get; }
|
||||
protected abstract void SetUpUI();
|
||||
|
||||
// Optional accessors
|
||||
protected virtual ProvinceId? TargetedProvince
|
||||
{
|
||||
protected virtual ProvinceId? TargetedProvince {
|
||||
get => null;
|
||||
set {}
|
||||
}
|
||||
public virtual List<ProvinceId> TargetedProvinces
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TargetedFactionIds.Count > 0)
|
||||
{
|
||||
public virtual List<ProvinceId> TargetedProvinces {
|
||||
get {
|
||||
if (TargetedFactionIds.Count > 0) {
|
||||
var list = new List<ProvinceId>();
|
||||
foreach (ProvinceView province in _model.Provinces.Values)
|
||||
{
|
||||
if (province.RulingFactionId is FactionId fid && TargetedFactionIds.Contains(fid))
|
||||
{
|
||||
foreach (ProvinceView province in _model.Provinces.Values) {
|
||||
if (province.RulingFactionId is FactionId fid &&
|
||||
TargetedFactionIds.Contains(fid)) {
|
||||
list.Add(province.Id);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (TargetedProvince is ProvinceId pid)
|
||||
{
|
||||
if (TargetedProvince is ProvinceId pid) {
|
||||
return new List<ProvinceId> { pid };
|
||||
} else
|
||||
return new List<ProvinceId>();
|
||||
}
|
||||
else return new List<ProvinceId>();
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value.Count)
|
||||
{
|
||||
set {
|
||||
switch (value.Count) {
|
||||
case 0: return;
|
||||
case 1: TargetedProvince = value[0]; break;
|
||||
default:
|
||||
throw new ArgumentException("Unable to handle multiple targeted provinces in default");
|
||||
throw new ArgumentException(
|
||||
"Unable to handle multiple targeted provinces in default");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,26 +75,18 @@ namespace eagle
|
||||
public GameObject Panel => gameObject;
|
||||
|
||||
protected FocusInfoPanelController _focusInfoPanelController;
|
||||
public void SetFocusInfoPanelController(FocusInfoPanelController newController)
|
||||
{
|
||||
public void SetFocusInfoPanelController(FocusInfoPanelController newController) {
|
||||
_focusInfoPanelController = newController;
|
||||
}
|
||||
|
||||
protected GameModel _model = null;
|
||||
protected AvailableCommand _availableCommand = null;
|
||||
|
||||
public void Show()
|
||||
{
|
||||
Panel.gameObject.SetActive(true);
|
||||
}
|
||||
public void Show() { Panel.gameObject.SetActive(true); }
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
Panel.gameObject.SetActive(false);
|
||||
}
|
||||
public void Hide() { Panel.gameObject.SetActive(false); }
|
||||
|
||||
public void UpdateAvailableCommand(GameModel model, AvailableCommand ac)
|
||||
{
|
||||
public void UpdateAvailableCommand(GameModel model, AvailableCommand ac) {
|
||||
_model = model;
|
||||
_availableCommand = ac;
|
||||
SetUpUI();
|
||||
|
||||
+36
-39
@@ -6,76 +6,76 @@ using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using EagleGUIUtils;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using static Net.Eagle0.Eagle.Api.ControlWeatherAvailableCommand.Types;
|
||||
using HeroId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class ControlWeatherCommandSelector : CommandSelector
|
||||
{
|
||||
public class ControlWeatherCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public TMP_Dropdown targetDropdown;
|
||||
public TMP_Dropdown actionDropdown;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ControlWeatherAvailableCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ControlWeatherAvailableCommand;
|
||||
public override string HeaderString => "Control Weather";
|
||||
public override string CommitButtonString => $"Commit {DisplayNames.ControlWeatherTypeName(SelectedOption.ControlWeatherTypes[actionDropdown.value])}";
|
||||
public override string CommitButtonString =>
|
||||
$"Commit {DisplayNames.ControlWeatherTypeName(SelectedOption.ControlWeatherTypes[actionDropdown.value])}";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => ControlWeatherAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
ControlWeatherAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private ControlWeatherAvailableCommand ControlWeatherAvailableCommand => _availableCommand.ControlWeatherAvailableCommand;
|
||||
private ControlWeatherAvailableCommand ControlWeatherAvailableCommand =>
|
||||
_availableCommand.ControlWeatherAvailableCommand;
|
||||
|
||||
private TargetProvinceOptions SelectedOption => ControlWeatherAvailableCommand.Options[targetDropdown.value];
|
||||
private ControlWeatherType SelectedType => SelectedOption.ControlWeatherTypes[actionDropdown.value];
|
||||
private TargetProvinceOptions SelectedOption =>
|
||||
ControlWeatherAvailableCommand.Options[targetDropdown.value];
|
||||
private ControlWeatherType SelectedType =>
|
||||
SelectedOption.ControlWeatherTypes[actionDropdown.value];
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => SelectedOption.ProvinceId;
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
int index = ControlWeatherAvailableCommand.Options.ToList().FindIndex(tpo => tpo.ProvinceId == value.Value);
|
||||
if (index != -1)
|
||||
targetDropdown.value = index;
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index = ControlWeatherAvailableCommand.Options.ToList().FindIndex(
|
||||
tpo => tpo.ProvinceId == value.Value);
|
||||
if (index != -1) targetDropdown.value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand
|
||||
{
|
||||
ControlWeatherSelectedCommand = new ControlWeatherSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ControlWeatherSelectedCommand =
|
||||
new ControlWeatherSelectedCommand {
|
||||
SelectedProvinceId = SelectedOption.ProvinceId,
|
||||
SelectedType = SelectedType,
|
||||
ActingHeroId = SelectedHeroId
|
||||
}
|
||||
};
|
||||
|
||||
public void SetOptions()
|
||||
{
|
||||
public void SetOptions() {
|
||||
var availableTypes = SelectedOption.ControlWeatherTypes;
|
||||
actionDropdown.ClearOptions();
|
||||
actionDropdown.AddOptions(availableTypes.Select(tp => DisplayNames.ControlWeatherTypeName(tp)).ToList());
|
||||
actionDropdown.AddOptions(
|
||||
availableTypes.Select(tp => DisplayNames.ControlWeatherTypeName(tp)).ToList());
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = ControlWeatherAvailableCommand
|
||||
.AvailableHeroIds
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes = ControlWeatherAvailableCommand.AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
|
||||
targetDropdown.ClearOptions();
|
||||
var destinationProvinceNames = ControlWeatherAvailableCommand.Options
|
||||
.Select(opt => opt.ProvinceId)
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
var destinationProvinceNames =
|
||||
ControlWeatherAvailableCommand.Options.Select(opt => opt.ProvinceId)
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList();
|
||||
|
||||
targetDropdown.AddOptions(destinationProvinceNames);
|
||||
@@ -84,9 +84,6 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+73
-76
@@ -5,65 +5,73 @@ using Net.Eagle0.Eagle.Common;
|
||||
using EagleGUIUtils;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using BattalionId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
using HeroId = System.Int32;
|
||||
|
||||
public class DefendCommandSelector : CommandSelector
|
||||
{
|
||||
public class DefendCommandSelector : CommandSelector {
|
||||
private int RallyPointProvinceIndex => rallyPointDropdown.value;
|
||||
private List<CombatUnit> SelectedActingUnits => unitSelector.SelectedActingUnits;
|
||||
|
||||
public EventBasedUnitSelector unitSelector;
|
||||
public TMP_Dropdown rallyPointDropdown;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.DefendCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.DefendCommand;
|
||||
public override string HeaderString => "Defend";
|
||||
public override string CommitButtonString => "Commit Defend";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => unitSelector.SelectedIds.Where(u => u.heroId.HasValue).Select(u => u.heroId.Value).ToList();
|
||||
public override bool HeroIsTargetable(HeroId heroId) => unitSelector.HeroIsTargetable(heroId);
|
||||
public override List<HeroId> TargetedHeroIds =>
|
||||
unitSelector.SelectedIds.Where(u => u.heroId.HasValue)
|
||||
.Select(u => u.heroId.Value)
|
||||
.ToList();
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
unitSelector.HeroIsTargetable(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => unitSelector.AddTargetedHero(heroId);
|
||||
public override void RemoveTargetedHero(HeroId heroId) => unitSelector.RemoveTargetedHero(heroId);
|
||||
public override void RemoveTargetedHero(HeroId heroId) =>
|
||||
unitSelector.RemoveTargetedHero(heroId);
|
||||
|
||||
public override List<BattalionId> TargetedBattalionIds => unitSelector.SelectedIds.Where(u => u.battalion != null).Select(u => u.battalion.Id).ToList();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) => unitSelector.BattalionIsTargetable(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) => unitSelector.AddTargetedBattalion(bid);
|
||||
public override void RemoveTargetedBattalion(BattalionId bid) => unitSelector.RemoveTargetedBattalion(bid);
|
||||
public override List<BattalionId> TargetedBattalionIds =>
|
||||
unitSelector.SelectedIds.Where(u => u.battalion != null)
|
||||
.Select(u => u.battalion.Id)
|
||||
.ToList();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) =>
|
||||
unitSelector.BattalionIsTargetable(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) =>
|
||||
unitSelector.AddTargetedBattalion(bid);
|
||||
public override void RemoveTargetedBattalion(BattalionId bid) =>
|
||||
unitSelector.RemoveTargetedBattalion(bid);
|
||||
|
||||
private DefendAvailableCommand DefendCommand => _availableCommand.DefendCommand;
|
||||
private ProvinceId ActingProvinceId => DefendCommand.ActingProvinceId;
|
||||
|
||||
private ProvinceId? RallyPointProvinceId => DefendCommand.AvailableFleeProvinceIds.Count > 0 ? DefendCommand.AvailableFleeProvinceIds[RallyPointProvinceIndex] : (ProvinceId?)null;
|
||||
private ProvinceId? RallyPointProvinceId =>
|
||||
DefendCommand.AvailableFleeProvinceIds.Count >
|
||||
0? DefendCommand.AvailableFleeProvinceIds[RallyPointProvinceIndex]
|
||||
: (ProvinceId?)null;
|
||||
|
||||
private bool BadlyConstructedUnits => unitSelector.HeroIdsLeadingInappropriateUnits.Count > 0;
|
||||
private bool BadlyConstructedUnits =>
|
||||
unitSelector.HeroIdsLeadingInappropriateUnits.Count > 0;
|
||||
|
||||
private bool NoBattalions => unitSelector.BattalionCount == 0 && DefendCommand.AvailableBattalions.Count > 0;
|
||||
private bool NoBattalions =>
|
||||
unitSelector.BattalionCount == 0 && DefendCommand.AvailableBattalions.Count > 0;
|
||||
|
||||
public override bool WarnOnCommitButton => BadlyConstructedUnits || NoBattalions;
|
||||
public override string CommitWarningText
|
||||
{
|
||||
get
|
||||
{
|
||||
public override string CommitWarningText {
|
||||
get {
|
||||
if (!(WarnOnCommitButton)) return null;
|
||||
|
||||
string txt = "";
|
||||
if (NoBattalions)
|
||||
{
|
||||
txt = txt + "You have not selected any troops.\n\n";
|
||||
}
|
||||
if (BadlyConstructedUnits)
|
||||
{
|
||||
if (NoBattalions) { txt = txt + "You have not selected any troops.\n\n"; }
|
||||
if (BadlyConstructedUnits) {
|
||||
var count = unitSelector.HeroIdsLeadingInappropriateUnits.Count;
|
||||
if (count == 1)
|
||||
{
|
||||
txt = txt + $"{_model.Heroes[unitSelector.HeroIdsLeadingInappropriateUnits[0]].Name} is leading a battalion type that would restrict their abilities.\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = txt + $"Some of your heroes are leading battalion types that would restrict their abilities.\n\n";
|
||||
if (count == 1) {
|
||||
txt = txt +
|
||||
$"{_model.Heroes[unitSelector.HeroIdsLeadingInappropriateUnits[0]].Name} is leading a battalion type that would restrict their abilities.\n\n";
|
||||
} else {
|
||||
txt = txt +
|
||||
$"Some of your heroes are leading battalion types that would restrict their abilities.\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,17 +79,13 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => RallyPointProvinceId;
|
||||
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index = DefendCommand.AvailableFleeProvinceIds.IndexOf(value.Value);
|
||||
if (index != -1)
|
||||
rallyPointDropdown.value = index;
|
||||
if (index != -1) rallyPointDropdown.value = index;
|
||||
else
|
||||
rallyPointDropdown.value = 0;
|
||||
}
|
||||
@@ -91,11 +95,11 @@ namespace eagle
|
||||
public override bool EnableCommitButton => unitSelector.UnitsAreValid;
|
||||
public override string DisabledCommitButtonReason => unitSelector.InvalidUnitsReason;
|
||||
|
||||
private void SetUpRallyPointProvinceDropdown()
|
||||
{
|
||||
var destinationProvinceNames = DefendCommand
|
||||
.AvailableFleeProvinceIds
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
private void SetUpRallyPointProvinceDropdown() {
|
||||
var destinationProvinceNames = DefendCommand.AvailableFleeProvinceIds
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList();
|
||||
|
||||
rallyPointDropdown.ClearOptions();
|
||||
@@ -103,19 +107,25 @@ namespace eagle
|
||||
rallyPointDropdown.value = 0;
|
||||
}
|
||||
|
||||
private void SetUpUnitSelector()
|
||||
{
|
||||
var dict = new Dictionary<HeroId, List<Net.Eagle0.Eagle.Api.Command.Util.SuitableBattalions.Types.BattalionIdWithSuitability>>();
|
||||
foreach (var kv in DefendCommand.SuitableBattalionsForHeroes)
|
||||
{
|
||||
private void SetUpUnitSelector() {
|
||||
var dict = new Dictionary<
|
||||
HeroId,
|
||||
List<Net.Eagle0.Eagle.Api.Command.Util.SuitableBattalions.Types
|
||||
.BattalionIdWithSuitability>>();
|
||||
foreach (var kv in DefendCommand.SuitableBattalionsForHeroes) {
|
||||
dict.Add(kv.Key, kv.Value.BattalionIdsWithSuitability.ToList());
|
||||
}
|
||||
|
||||
List<CombatUnit> recommendedUnits = DefendCommand.RecommendedUnits == null ? new List<CombatUnit>() : DefendCommand.RecommendedUnits.ToList();
|
||||
List<CombatUnit> recommendedUnits = DefendCommand.RecommendedUnits == null
|
||||
? new List<CombatUnit>()
|
||||
: DefendCommand.RecommendedUnits.ToList();
|
||||
|
||||
var province = _model.Provinces[ActingProvinceId];
|
||||
var availableBattalionIds = DefendCommand.AvailableBattalions.Select(b => b.BattalionId).ToList();
|
||||
var orderedBattalions = ProvinceUtils.OrderedBattalions(province).Where(batt => availableBattalionIds.Contains(batt.Id)).ToList();
|
||||
var availableBattalionIds =
|
||||
DefendCommand.AvailableBattalions.Select(b => b.BattalionId).ToList();
|
||||
var orderedBattalions = ProvinceUtils.OrderedBattalions(province)
|
||||
.Where(batt => availableBattalionIds.Contains(batt.Id))
|
||||
.ToList();
|
||||
|
||||
unitSelector.SetUpUnits(
|
||||
_model,
|
||||
@@ -125,12 +135,10 @@ namespace eagle
|
||||
recommendedUnits);
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
if (DefendCommand.AvailableFleeProvinceIds.Count > 0)
|
||||
{
|
||||
var availableRallyPointProvinceNames = DefendCommand
|
||||
.AvailableFleeProvinceIds
|
||||
protected override void SetUpUI() {
|
||||
if (DefendCommand.AvailableFleeProvinceIds.Count > 0) {
|
||||
var availableRallyPointProvinceNames =
|
||||
DefendCommand.AvailableFleeProvinceIds
|
||||
.Select(pid => _model.Provinces[pid].Name)
|
||||
.ToList();
|
||||
|
||||
@@ -138,33 +146,22 @@ namespace eagle
|
||||
rallyPointDropdown.AddOptions(availableRallyPointProvinceNames);
|
||||
rallyPointDropdown.value = 0;
|
||||
rallyPointDropdown.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rallyPointDropdown.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
SetUpUnitSelector();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var dc = new DefendSelectedCommand();
|
||||
if (RallyPointProvinceId.HasValue)
|
||||
{
|
||||
dc = new DefendSelectedCommand
|
||||
{
|
||||
FleeProvinceId = RallyPointProvinceId.Value
|
||||
};
|
||||
if (RallyPointProvinceId.HasValue) {
|
||||
dc = new DefendSelectedCommand { FleeProvinceId = RallyPointProvinceId.Value };
|
||||
}
|
||||
dc.DefendingUnits.AddRange(SelectedActingUnits);
|
||||
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
DefendCommand = dc
|
||||
};
|
||||
var cmd = new SelectedCommand { DefendCommand = dc };
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
+67
-81
@@ -7,19 +7,21 @@ using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using FactionId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class DiplomacyCommandSelector : CommandSelector
|
||||
{
|
||||
public class DiplomacyCommandSelector : CommandSelector {
|
||||
private HeroId SelectedHeroId => ambassadorDropdownController.SelectedHeroId;
|
||||
private FactionId SelectedFactionId => AvailableTargetFactionIds[targetFactionDropdown.value];
|
||||
private FactionId SelectedFactionId =>
|
||||
AvailableTargetFactionIds[targetFactionDropdown.value];
|
||||
|
||||
public override bool IsAppropriateFor(AvailableCommand cmd) =>
|
||||
cmd.SealedValueCase == CommandType && cmd.DiplomacyCommand.Options.Any(opt => opt.SealedValueCase != DiplomacyOption.SealedValueOneofCase.RansomOfferOption);
|
||||
cmd.SealedValueCase == CommandType
|
||||
&& cmd.DiplomacyCommand.Options.Any(
|
||||
opt => opt.SealedValueCase !=
|
||||
DiplomacyOption.SealedValueOneofCase.RansomOfferOption);
|
||||
|
||||
private DiplomacyAvailableCommand DiplomacyCommand => _availableCommand.DiplomacyCommand;
|
||||
private ProvinceId ActingProvinceId => DiplomacyCommand.ActingProvinceId;
|
||||
@@ -34,59 +36,59 @@ namespace eagle
|
||||
public TMP_Text allianceLabel;
|
||||
public TMP_Text inviteLabel;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.DiplomacyCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.DiplomacyCommand;
|
||||
public override string HeaderString => "Diplomacy";
|
||||
public override string CommitButtonString
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (SelectedDiplomacyOptionType)
|
||||
{
|
||||
public override string CommitButtonString {
|
||||
get {
|
||||
switch (SelectedDiplomacyOptionType) {
|
||||
case DiplomacyOption.SealedValueOneofCase.TreatyOption:
|
||||
return "Commit Treaty Offer";
|
||||
case DiplomacyOption.SealedValueOneofCase.InvitationOption:
|
||||
return "Commit Invite";
|
||||
default:
|
||||
throw new KeyNotFoundException("Unknown diplomacy option");
|
||||
default: throw new KeyNotFoundException("Unknown diplomacy option");
|
||||
}
|
||||
}
|
||||
}
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => DiplomacyCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => ambassadorDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
DiplomacyCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
ambassadorDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
public override List<FactionId> TargetedFactionIds => new List<FactionId> { SelectedFactionId };
|
||||
public override bool FactionIsTargetable(FactionId factionId) => AvailableTargetFactionIds.Contains(factionId);
|
||||
public override void AddTargetedFaction(FactionId factionId) => targetFactionDropdown.value = AvailableTargetFactionIds.IndexOf(factionId);
|
||||
public override List<FactionId> TargetedFactionIds =>
|
||||
new List<FactionId> { SelectedFactionId };
|
||||
public override bool FactionIsTargetable(FactionId factionId) =>
|
||||
AvailableTargetFactionIds.Contains(factionId);
|
||||
public override void AddTargetedFaction(FactionId factionId) =>
|
||||
targetFactionDropdown.value = AvailableTargetFactionIds.IndexOf(factionId);
|
||||
|
||||
public override bool WarnOnCommitButton => _model.ActiveFactions[_model.PlayerId.Value].Leaders.Contains(ambassadorDropdownController.SelectedHeroId);
|
||||
public override string CommitWarningText => "You're putting your faction leader at risk. Are you sure?";
|
||||
public override bool WarnOnCommitButton =>
|
||||
_model.ActiveFactions[_model.PlayerId.Value].Leaders.Contains(
|
||||
ambassadorDropdownController.SelectedHeroId);
|
||||
public override string CommitWarningText =>
|
||||
"You're putting your faction leader at risk. Are you sure?";
|
||||
|
||||
private List<FactionId> AvailableTargetFactionIds { get; set; }
|
||||
|
||||
private DiplomacyOption.SealedValueOneofCase SelectedDiplomacyOptionType
|
||||
{
|
||||
get
|
||||
{
|
||||
private DiplomacyOption.SealedValueOneofCase SelectedDiplomacyOptionType {
|
||||
get {
|
||||
if (allianceToggle.isOn) return DiplomacyOption.SealedValueOneofCase.TreatyOption;
|
||||
else if (inviteToggle.isOn) return DiplomacyOption.SealedValueOneofCase.InvitationOption;
|
||||
else throw new KeyNotFoundException("Unknown diplomacy option");
|
||||
else if (inviteToggle.isOn)
|
||||
return DiplomacyOption.SealedValueOneofCase.InvitationOption;
|
||||
else
|
||||
throw new KeyNotFoundException("Unknown diplomacy option");
|
||||
}
|
||||
}
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => null;
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
var targetFaction = _model.Provinces[value.Value].RulingFactionId;
|
||||
if (targetFaction.HasValue)
|
||||
{
|
||||
if (targetFaction.HasValue) {
|
||||
var dropdownIndex = AvailableTargetFactionIds.IndexOf(targetFaction.Value);
|
||||
if (dropdownIndex != -1)
|
||||
{
|
||||
if (dropdownIndex != -1) {
|
||||
targetFactionDropdown.value = dropdownIndex;
|
||||
SetOptions();
|
||||
costText.text = SelectedOptionCost.ToString();
|
||||
@@ -96,86 +98,73 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
private FactionId TargetFactionId(DiplomacyOption option)
|
||||
{
|
||||
switch (option.SealedValueCase)
|
||||
{
|
||||
private FactionId TargetFactionId(DiplomacyOption option) {
|
||||
switch (option.SealedValueCase) {
|
||||
case DiplomacyOption.SealedValueOneofCase.TreatyOption:
|
||||
return option.TreatyOption.TargetFactionId;
|
||||
|
||||
case DiplomacyOption.SealedValueOneofCase.InvitationOption:
|
||||
return option.InvitationOption.TargetFactionId;
|
||||
|
||||
default:
|
||||
throw new System.ArgumentException("Unknown diplomacy option");
|
||||
default: throw new System.ArgumentException("Unknown diplomacy option");
|
||||
}
|
||||
}
|
||||
|
||||
private int GoldCost(DiplomacyOption option)
|
||||
{
|
||||
switch (option.SealedValueCase)
|
||||
{
|
||||
private int GoldCost(DiplomacyOption option) {
|
||||
switch (option.SealedValueCase) {
|
||||
case DiplomacyOption.SealedValueOneofCase.TreatyOption:
|
||||
return option.TreatyOption.GoldCost;
|
||||
|
||||
case DiplomacyOption.SealedValueOneofCase.InvitationOption:
|
||||
return option.InvitationOption.GoldCost;
|
||||
|
||||
default:
|
||||
throw new System.ArgumentException("Unknown diplomacy option");
|
||||
default: throw new System.ArgumentException("Unknown diplomacy option");
|
||||
}
|
||||
}
|
||||
|
||||
private DiplomacyOption SelectedOption =>
|
||||
DiplomacyCommand.Options.First(opt => opt.SealedValueCase == SelectedDiplomacyOptionType && TargetFactionId(opt) == SelectedFactionId);
|
||||
private DiplomacyOption SelectedOption => DiplomacyCommand.Options.First(
|
||||
opt => opt.SealedValueCase == SelectedDiplomacyOptionType &&
|
||||
TargetFactionId(opt) == SelectedFactionId);
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
ambassadorDropdownController.AvailableHeroes = DiplomacyCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid]).ToList();
|
||||
protected override void SetUpUI() {
|
||||
ambassadorDropdownController.AvailableHeroes =
|
||||
DiplomacyCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid]).ToList();
|
||||
ambassadorDropdownController.SelectedHeroId = DiplomacyCommand.RecommendedHeroId;
|
||||
|
||||
AvailableTargetFactionIds = DiplomacyCommand
|
||||
.Options
|
||||
.Where(opt => opt.SealedValueCase != DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
AvailableTargetFactionIds =
|
||||
DiplomacyCommand.Options
|
||||
.Where(opt => opt.SealedValueCase !=
|
||||
DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
.Select(opt => TargetFactionId(opt))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
targetFactionDropdown.ClearOptions();
|
||||
targetFactionDropdown.AddOptions(
|
||||
AvailableTargetFactionIds
|
||||
.Select(fid => _model.FactionName(fid))
|
||||
.ToList());
|
||||
AvailableTargetFactionIds.Select(fid => _model.FactionName(fid)).ToList());
|
||||
targetFactionDropdown.value = 0;
|
||||
|
||||
SetOptions();
|
||||
costText.text = SelectedOptionCost.ToString();
|
||||
}
|
||||
|
||||
public void ToggleChanged()
|
||||
{
|
||||
costText.text = SelectedOptionCost.ToString();
|
||||
}
|
||||
public void ToggleChanged() { costText.text = SelectedOptionCost.ToString(); }
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
DiplomacyCommand = new DiplomacySelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
DiplomacyCommand =
|
||||
new DiplomacySelectedCommand {
|
||||
SentHeroId = SelectedHeroId,
|
||||
TargetFactionId = SelectedFactionId,
|
||||
SelectedOption = SelectedOption
|
||||
}
|
||||
};
|
||||
|
||||
public void TargetDropdownChanged(int value)
|
||||
{
|
||||
SetOptions();
|
||||
}
|
||||
public void TargetDropdownChanged(int value) { SetOptions(); }
|
||||
|
||||
private void SetOptions()
|
||||
{
|
||||
private void SetOptions() {
|
||||
var targetFid = SelectedFactionId;
|
||||
var enableInvite = DiplomacyCommand.Options.Any(opt => opt.InvitationOption != null && TargetFactionId(opt) == targetFid);
|
||||
var enableInvite = DiplomacyCommand.Options.Any(
|
||||
opt => opt.InvitationOption != null && TargetFactionId(opt) == targetFid);
|
||||
|
||||
if (!enableInvite) allianceToggle.isOn = true;
|
||||
ConditionallyEnable(inviteToggle, inviteLabel, enableInvite);
|
||||
@@ -183,16 +172,13 @@ namespace eagle
|
||||
costText.text = SelectedOptionCost.ToString();
|
||||
}
|
||||
|
||||
private void ConditionallyEnable(Toggle toggle, TMP_Text label, bool enable)
|
||||
{
|
||||
private void ConditionallyEnable(Toggle toggle, TMP_Text label, bool enable) {
|
||||
toggle.gameObject.SetActive(enable);
|
||||
Color color = label.color;
|
||||
color.a = enable ? 1.0f : 0.25f;
|
||||
label.color = color;
|
||||
}
|
||||
|
||||
private int SelectedOptionCost => _availableCommand != null
|
||||
? GoldCost(SelectedOption)
|
||||
: 0;
|
||||
private int SelectedOptionCost => _availableCommand != null ? GoldCost(SelectedOption) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-45
@@ -5,13 +5,11 @@ using Net.Eagle0.Eagle.Api;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class DivineCommandSelector : CommandSelector
|
||||
{
|
||||
public class DivineCommandSelector : CommandSelector {
|
||||
public HeroDetailsController heroDetails;
|
||||
public TMP_Text goldCostLabel;
|
||||
public Button nextHeroButton;
|
||||
@@ -23,29 +21,31 @@ namespace eagle
|
||||
private DivineAvailableCommand DivineCommand => _availableCommand.DivineCommand;
|
||||
private ProvinceId ActingProvinceId => DivineCommand.ActingProvinceId;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.DivineCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.DivineCommand;
|
||||
public override string HeaderString => "Divine Heroes";
|
||||
public override string CommitButtonString => divineAllSelected ? "Commit Divine All" : "Commit Divine";
|
||||
public override string CommitButtonString =>
|
||||
divineAllSelected ? "Commit Divine All" : "Commit Divine";
|
||||
|
||||
public override bool HeroIsTargetable(HeroId heroId) => DivineCommand.DivinableHeroes.Any(uh => uh.Hero.Id == heroId);
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
DivineCommand.DivinableHeroes.Any(uh => uh.Hero.Id == heroId);
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
|
||||
private int _selectedHeroIndex;
|
||||
private HeroView SelectedHero => DivineCommand.DivinableHeroes.ToArray()[_selectedHeroIndex].Hero;
|
||||
private HeroView SelectedHero =>
|
||||
DivineCommand.DivinableHeroes.ToArray()[_selectedHeroIndex].Hero;
|
||||
private HeroId SelectedHeroId => SelectedHero.Id;
|
||||
private int DivinableCount => DivineCommand.DivinableHeroes.Count;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
if (_selectedHeroIndex >= DivinableCount)
|
||||
{
|
||||
_selectedHeroIndex = 0;
|
||||
}
|
||||
protected override void SetUpUI() {
|
||||
if (_selectedHeroIndex >= DivinableCount) { _selectedHeroIndex = 0; }
|
||||
heroDetails.SetHero(SelectedHero, _model);
|
||||
|
||||
nextHeroButton.gameObject.SetActive(DivinableCount > 1);
|
||||
|
||||
bool enableDivineAll = DivinableCount > 1 && _model.Provinces[ActingProvinceId].FullInfo.Gold >= DivinableCount * DivineCommand.CostPerHero;
|
||||
bool enableDivineAll =
|
||||
DivinableCount > 1 && _model.Provinces[ActingProvinceId].FullInfo.Gold >=
|
||||
DivinableCount * DivineCommand.CostPerHero;
|
||||
divineAllToggle.enabled = enableDivineAll;
|
||||
divineAllToggle.gameObject.SetActive(enableDivineAll);
|
||||
divineAllText.text = $"Divine All ({DivinableCount})";
|
||||
@@ -56,53 +56,34 @@ namespace eagle
|
||||
SetCostLabel();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var dc = new DivineSelectedCommand();
|
||||
if (divineAllSelected)
|
||||
{
|
||||
if (divineAllSelected) {
|
||||
dc.HeroIds.Add(DivineCommand.DivinableHeroes.Select(h => h.Hero.Id));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dc.HeroIds.Add(SelectedHeroId);
|
||||
}
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
DivineCommand = dc
|
||||
};
|
||||
var cmd = new SelectedCommand { DivineCommand = dc };
|
||||
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
public void NextHero()
|
||||
{
|
||||
public void NextHero() {
|
||||
_selectedHeroIndex++;
|
||||
if (_selectedHeroIndex >= DivinableCount)
|
||||
{
|
||||
_selectedHeroIndex = 0;
|
||||
}
|
||||
if (_selectedHeroIndex >= DivinableCount) { _selectedHeroIndex = 0; }
|
||||
heroDetails.SetHero(SelectedHero, _model);
|
||||
}
|
||||
|
||||
private void SetCostLabel()
|
||||
{
|
||||
if (divineAllToggle.isOn)
|
||||
{
|
||||
private void SetCostLabel() {
|
||||
if (divineAllToggle.isOn) {
|
||||
goldCostLabel.text = (DivineCommand.CostPerHero * DivinableCount).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
goldCostLabel.text = DivineCommand.CostPerHero.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleClicked(bool value)
|
||||
{
|
||||
SetCostLabel();
|
||||
}
|
||||
public void ToggleClicked(bool value) { SetCostLabel(); }
|
||||
}
|
||||
}
|
||||
|
||||
+18
-25
@@ -4,19 +4,18 @@ using System.Linq;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class ExileVassalCommandSelector : CommandSelector
|
||||
{
|
||||
public class ExileVassalCommandSelector : CommandSelector {
|
||||
// Unity accessors
|
||||
public HeroDropdownController heroSelectionDropdownController;
|
||||
|
||||
public HeroDetailsController heroDetails;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ExileVassalCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ExileVassalCommand;
|
||||
public override string HeaderString => "Exile Vassal";
|
||||
public override string CommitButtonString => $"Commit Exile";
|
||||
|
||||
@@ -24,34 +23,28 @@ namespace eagle
|
||||
public HeroView SelectedHero => _model.Heroes[SelectedHeroId];
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => ExileVassalAvailableCommand.ExilableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroSelectionDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
ExileVassalAvailableCommand.ExilableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroSelectionDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private ExileVassalAvailableCommand ExileVassalAvailableCommand => _availableCommand.ExileVassalCommand;
|
||||
private ExileVassalAvailableCommand ExileVassalAvailableCommand =>
|
||||
_availableCommand.ExileVassalCommand;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroSelectionDropdownController.AvailableHeroes = ExileVassalAvailableCommand.ExilableHeroIds.Select(hid => _model.Heroes[hid]).ToList();
|
||||
protected override void SetUpUI() {
|
||||
heroSelectionDropdownController.AvailableHeroes =
|
||||
ExileVassalAvailableCommand.ExilableHeroIds.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
heroSelectionDropdownController.SelectedHeroIdUpdated = () => DisplaySelectedHero();
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ExileVassalCommand = new ExileVassalSelectedCommand
|
||||
{
|
||||
ExiledHeroId = SelectedHeroId
|
||||
}
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ExileVassalCommand = new ExileVassalSelectedCommand { ExiledHeroId = SelectedHeroId }
|
||||
};
|
||||
|
||||
public void DropdownSelected(int value)
|
||||
{
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
public void DropdownSelected(int value) { DisplaySelectedHero(); }
|
||||
|
||||
private void DisplaySelectedHero()
|
||||
{
|
||||
heroDetails.SetHero(SelectedHero, _model);
|
||||
}
|
||||
private void DisplaySelectedHero() { heroDetails.SetHero(SelectedHero, _model); }
|
||||
}
|
||||
}
|
||||
|
||||
+7
-11
@@ -3,13 +3,12 @@ using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class FeastCommandSelector : CommandSelector
|
||||
{
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.FeastCommand;
|
||||
public class FeastCommandSelector : CommandSelector {
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.FeastCommand;
|
||||
public override string HeaderString => "Feast";
|
||||
public override string CommitButtonString => "Commit Feast";
|
||||
|
||||
@@ -18,13 +17,10 @@ namespace eagle
|
||||
private FeastAvailableCommand FeastAvailableCommand => _availableCommand.FeastCommand;
|
||||
private ProvinceId ActingProvinceId => FeastAvailableCommand.ActingProvinceId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
FeastCommand = new FeastSelectedCommand()
|
||||
};
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand { FeastCommand = new FeastSelectedCommand() };
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
GoldCostLabel.text = _availableCommand.FeastCommand.GoldCost.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-25
@@ -6,55 +6,52 @@ using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class FreeForAllDecisionCommandSelector : CommandSelector
|
||||
{
|
||||
public class FreeForAllDecisionCommandSelector : CommandSelector {
|
||||
public EventBasedTable unitsTable;
|
||||
public EventBasedTable armiesTable;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.FreeForAllDecisionCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.FreeForAllDecisionCommand;
|
||||
public override string HeaderString => "Free-For-All Decision";
|
||||
public override string CommitButtonString => AdvanceToggle.isOn ? "Commit Advance" : "Commit Withdraw";
|
||||
public override string CommitButtonString =>
|
||||
AdvanceToggle.isOn ? "Commit Advance" : "Commit Withdraw";
|
||||
|
||||
public Toggle AdvanceToggle;
|
||||
public Toggle WithdrawToggle;
|
||||
|
||||
private FreeForAllDecisionAvailableCommand FreeForAllDecisionCommand => _availableCommand.FreeForAllDecisionCommand;
|
||||
private FreeForAllDecisionAvailableCommand FreeForAllDecisionCommand =>
|
||||
_availableCommand.FreeForAllDecisionCommand;
|
||||
private ProvinceId ActingProvinceId => FreeForAllDecisionCommand.ProvinceId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
FreeForAllDecisionCommand = new FreeForAllDecisionSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
FreeForAllDecisionCommand =
|
||||
new FreeForAllDecisionSelectedCommand {
|
||||
ProvinceId = ActingProvinceId,
|
||||
Decision = AdvanceToggle.isOn ? AttackDecisionType.AdvanceDecision : AttackDecisionType.WithdrawDecision
|
||||
Decision = AdvanceToggle.isOn ? AttackDecisionType.AdvanceDecision
|
||||
: AttackDecisionType.WithdrawDecision
|
||||
}
|
||||
};
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
unitsTable.RowCount = FreeForAllDecisionCommand.ActingUnits.Count;
|
||||
ProvinceView province = _model.Provinces[ActingProvinceId];
|
||||
|
||||
FreeForAllDecisionCommand.ActingUnits.Each((cu, idx) =>
|
||||
{
|
||||
FreeForAllDecisionCommand.ActingUnits.Each((cu, idx) => {
|
||||
CombatUnitRowController row = unitsTable.ComponentAt<CombatUnitRowController>(idx);
|
||||
row.Hero = cu.Hero;
|
||||
row.Battalion = cu.Battalion;
|
||||
});
|
||||
|
||||
armiesTable.RowCount = FreeForAllDecisionCommand.Armies.Count;
|
||||
FreeForAllDecisionCommand.Armies.Each((army, idx) =>
|
||||
{
|
||||
FreeForAllDecisionCommand.Armies.Each((army, idx) => {
|
||||
IncomingArmyTableRow row = armiesTable.ComponentAt<IncomingArmyTableRow>(idx);
|
||||
row.Faction = _model.FactionName(army.FactionId);
|
||||
row.HeroCount = army.HeroCount;
|
||||
row.TroopCount = army.TroopCount;
|
||||
switch (army.Hostility)
|
||||
{
|
||||
switch (army.Hostility) {
|
||||
case Net.Eagle0.Common.Hostility.AlliedHostility:
|
||||
row.TextColor = Color.green;
|
||||
break;
|
||||
@@ -70,13 +67,11 @@ namespace eagle
|
||||
|
||||
AdvanceToggle.isOn = true;
|
||||
AdvanceToggle.enabled = true;
|
||||
WithdrawToggle.enabled = FreeForAllDecisionCommand.AvailableDecisions.Contains(AttackDecisionType.WithdrawDecision);
|
||||
WithdrawToggle.enabled = FreeForAllDecisionCommand.AvailableDecisions.Contains(
|
||||
AttackDecisionType.WithdrawDecision);
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
|
||||
+60
-50
@@ -5,12 +5,10 @@ using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class HandleCapturedHeroesCommandSelector : CommandSelector
|
||||
{
|
||||
public class HandleCapturedHeroesCommandSelector : CommandSelector {
|
||||
// Unity accessors
|
||||
public Toggle RecruitToggle;
|
||||
public Toggle ImprisonToggle;
|
||||
@@ -32,88 +30,101 @@ namespace eagle
|
||||
|
||||
public HeroView SelectedHero => SelectedHeroWithOptions.Hero;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.HandleCapturedHeroCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.HandleCapturedHeroCommand;
|
||||
public override string HeaderString => "Handle Captured Hero";
|
||||
public override string CommitButtonString => $"Commit {DisplayNames.CapturedHeroOptionNames[SelectedOption]}";
|
||||
public override string CommitButtonString =>
|
||||
$"Commit {DisplayNames.CapturedHeroOptionNames[SelectedOption]}";
|
||||
|
||||
private int _selectedHeroIndex;
|
||||
private ExpandedCapturedHero SelectedHeroWithOptions => HandleCapturedHeroCommand.AvailableHeroes[_selectedHeroIndex];
|
||||
private ExpandedCapturedHero SelectedHeroWithOptions =>
|
||||
HandleCapturedHeroCommand.AvailableHeroes[_selectedHeroIndex];
|
||||
|
||||
private HandleCapturedHeroAvailableCommand HandleCapturedHeroCommand => _availableCommand.HandleCapturedHeroCommand;
|
||||
private HandleCapturedHeroAvailableCommand HandleCapturedHeroCommand =>
|
||||
_availableCommand.HandleCapturedHeroCommand;
|
||||
private ProvinceId ActingProvinceId => HandleCapturedHeroCommand.ActingProvinceId;
|
||||
|
||||
public override bool WarnOnCommitButton => SelectedOption == CapturedHeroOption.ReturnCapturedHeroOption;
|
||||
public override string CommitWarningText => $"This will create a treaty with {_model.FactionName(SelectedHero.FactionId.Value)}";
|
||||
public override bool WarnOnCommitButton =>
|
||||
SelectedOption == CapturedHeroOption.ReturnCapturedHeroOption;
|
||||
public override string CommitWarningText =>
|
||||
$"This will create a treaty with {_model.FactionName(SelectedHero.FactionId.Value)}";
|
||||
|
||||
private CapturedHeroOption SelectedOption
|
||||
{
|
||||
get
|
||||
{
|
||||
private CapturedHeroOption SelectedOption {
|
||||
get {
|
||||
if (RecruitToggle.isOn) return CapturedHeroOption.RecruitCapturedHeroOption;
|
||||
else if (ImprisonToggle.isOn) return CapturedHeroOption.ImprisonCapturedHeroOption;
|
||||
else if (ExileToggle.isOn) return CapturedHeroOption.ExileCapturedHeroOption;
|
||||
else if (ExecuteToggle.isOn) return CapturedHeroOption.ExecuteCapturedHeroOption;
|
||||
else if (ReturnToggle.isOn) return CapturedHeroOption.ReturnCapturedHeroOption;
|
||||
else throw new ArgumentOutOfRangeException("Unknown captured hero option");
|
||||
else if (ImprisonToggle.isOn)
|
||||
return CapturedHeroOption.ImprisonCapturedHeroOption;
|
||||
else if (ExileToggle.isOn)
|
||||
return CapturedHeroOption.ExileCapturedHeroOption;
|
||||
else if (ExecuteToggle.isOn)
|
||||
return CapturedHeroOption.ExecuteCapturedHeroOption;
|
||||
else if (ReturnToggle.isOn)
|
||||
return CapturedHeroOption.ReturnCapturedHeroOption;
|
||||
else
|
||||
throw new ArgumentOutOfRangeException("Unknown captured hero option");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
if (_selectedHeroIndex >= HandleCapturedHeroCommand.AvailableHeroes.Count) _selectedHeroIndex = 0;
|
||||
NextHeroButton.gameObject.SetActive(HandleCapturedHeroCommand.AvailableHeroes.Count > 1);
|
||||
protected override void SetUpUI() {
|
||||
if (_selectedHeroIndex >= HandleCapturedHeroCommand.AvailableHeroes.Count)
|
||||
_selectedHeroIndex = 0;
|
||||
NextHeroButton.gameObject.SetActive(
|
||||
HandleCapturedHeroCommand.AvailableHeroes.Count > 1);
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
HandleCapturedHeroCommand = new HandleCapturedHeroSelectedCommand()
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
HandleCapturedHeroCommand =
|
||||
new HandleCapturedHeroSelectedCommand() {
|
||||
HeroId = SelectedHero.Id,
|
||||
SelectedOption = SelectedOption
|
||||
}
|
||||
};
|
||||
|
||||
public void NextHeroButtonClicked()
|
||||
{
|
||||
public void NextHeroButtonClicked() {
|
||||
_selectedHeroIndex++;
|
||||
if (_selectedHeroIndex >= HandleCapturedHeroCommand.AvailableHeroes.Count)
|
||||
{
|
||||
if (_selectedHeroIndex >= HandleCapturedHeroCommand.AvailableHeroes.Count) {
|
||||
_selectedHeroIndex = 0;
|
||||
}
|
||||
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
private void DisplaySelectedHero()
|
||||
{
|
||||
private void DisplaySelectedHero() {
|
||||
heroDetails.SetHero(SelectedHero, _model);
|
||||
|
||||
if (String.IsNullOrEmpty(SelectedHeroWithOptions.Message))
|
||||
{
|
||||
if (String.IsNullOrEmpty(SelectedHeroWithOptions.Message)) {
|
||||
MessageText.text = $"What should we do with {SelectedHero.Name}?";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
MessageText.text = SelectedHeroWithOptions.Message;
|
||||
}
|
||||
|
||||
// The order here is important: the last available toggle in this list
|
||||
// will be on by default
|
||||
ConditionallyEnable(ExecuteToggle, ExecuteIcon, CapturedHeroOption.ExecuteCapturedHeroOption);
|
||||
ConditionallyEnable(
|
||||
ExecuteToggle,
|
||||
ExecuteIcon,
|
||||
CapturedHeroOption.ExecuteCapturedHeroOption);
|
||||
ConditionallyEnable(ExileToggle, ExileIcon, CapturedHeroOption.ExileCapturedHeroOption);
|
||||
ConditionallyEnable(ReturnToggle, ReturnIcon, CapturedHeroOption.ReturnCapturedHeroOption);
|
||||
ConditionallyEnable(ImprisonToggle, ImprisonIcon, CapturedHeroOption.ImprisonCapturedHeroOption);
|
||||
ConditionallyEnable(RecruitToggle, RecruitIcon, CapturedHeroOption.RecruitCapturedHeroOption);
|
||||
ConditionallyEnable(
|
||||
ReturnToggle,
|
||||
ReturnIcon,
|
||||
CapturedHeroOption.ReturnCapturedHeroOption);
|
||||
ConditionallyEnable(
|
||||
ImprisonToggle,
|
||||
ImprisonIcon,
|
||||
CapturedHeroOption.ImprisonCapturedHeroOption);
|
||||
ConditionallyEnable(
|
||||
RecruitToggle,
|
||||
RecruitIcon,
|
||||
CapturedHeroOption.RecruitCapturedHeroOption);
|
||||
}
|
||||
|
||||
private bool ConditionallyEnable(Toggle toggle, CapturedHeroOption option)
|
||||
{
|
||||
private bool ConditionallyEnable(Toggle toggle, CapturedHeroOption option) {
|
||||
bool enable = SelectedHeroWithOptions.Options.Contains(option);
|
||||
toggle.gameObject.SetActive(enable);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if (enable) {
|
||||
ExecuteToggle.isOn = false;
|
||||
ExileToggle.isOn = false;
|
||||
ImprisonToggle.isOn = false;
|
||||
@@ -121,14 +132,13 @@ namespace eagle
|
||||
ReturnToggle.isOn = false;
|
||||
|
||||
toggle.isOn = true;
|
||||
}
|
||||
else toggle.isOn = false;
|
||||
} else
|
||||
toggle.isOn = false;
|
||||
|
||||
return enable;
|
||||
}
|
||||
|
||||
private void ConditionallyEnable(Toggle toggle, RawImage img, CapturedHeroOption option)
|
||||
{
|
||||
private void ConditionallyEnable(Toggle toggle, RawImage img, CapturedHeroOption option) {
|
||||
bool enable = ConditionallyEnable(toggle, option);
|
||||
|
||||
Color color = img.color;
|
||||
|
||||
+28
-22
@@ -6,18 +6,17 @@ using Net.Eagle0.Eagle.Api.Command;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using BattalionId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class HandleRiotCrackDownCommandSelector : CommandSelector
|
||||
{
|
||||
public class HandleRiotCrackDownCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public BattalionDropdownController battalionDropdownController;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.HandleRiotCrackDownAvailableCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.HandleRiotCrackDownAvailableCommand;
|
||||
|
||||
public override string HeaderString => "Crack Down";
|
||||
public override string CommitButtonString => "Commit Crack Down";
|
||||
@@ -26,42 +25,49 @@ namespace eagle
|
||||
public override string CommitWarningText => "You aren't sending a battalion. Are you sure?";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => HandleRiotCrackDownAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
HandleRiotCrackDownAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
public override List<BattalionId> TargetedBattalionIds => SelectedBattalionId.HasValue ? new List<BattalionId> { SelectedBattalionId.Value } : new List<BattalionId>();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) => HandleRiotCrackDownAvailableCommand.BattalionIdsAvailable.Contains(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) => battalionDropdownController.SelectedBattalionId = bid;
|
||||
public override List<BattalionId> TargetedBattalionIds =>
|
||||
SelectedBattalionId.HasValue ? new List<BattalionId> { SelectedBattalionId.Value }
|
||||
: new List<BattalionId>();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) =>
|
||||
HandleRiotCrackDownAvailableCommand.BattalionIdsAvailable.Contains(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) =>
|
||||
battalionDropdownController.SelectedBattalionId = bid;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
private BattalionId? SelectedBattalionId => battalionDropdownController.SelectedBattalionId;
|
||||
|
||||
private HandleRiotCrackDownAvailableCommand HandleRiotCrackDownAvailableCommand => _availableCommand.HandleRiotCrackDownAvailableCommand;
|
||||
private HandleRiotCrackDownAvailableCommand HandleRiotCrackDownAvailableCommand =>
|
||||
_availableCommand.HandleRiotCrackDownAvailableCommand;
|
||||
private ProvinceId ActingProvinceId => HandleRiotCrackDownAvailableCommand.ActingProvinceId;
|
||||
|
||||
private ProvinceView Province => _model.Provinces[ActingProvinceId];
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
HandleRiotCrackDownSelectedCommand = new HandleRiotCrackDownSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
HandleRiotCrackDownSelectedCommand =
|
||||
new HandleRiotCrackDownSelectedCommand {
|
||||
HeroId = SelectedHeroId,
|
||||
BattalionId = SelectedBattalionId
|
||||
}
|
||||
};
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = HandleRiotCrackDownAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
battalionDropdownController.AvailableBattalions = HandleRiotCrackDownAvailableCommand.BattalionIdsAvailable
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
HandleRiotCrackDownAvailableCommand.AvailableHeroIds
|
||||
.Select(id => _model.Heroes[id])
|
||||
.ToList();
|
||||
battalionDropdownController.AvailableBattalions =
|
||||
HandleRiotCrackDownAvailableCommand.BattalionIdsAvailable
|
||||
.Select(id => Province.FullInfo.Battalions.First(b => b.Id == id))
|
||||
.OrderBy(batt => batt.Type)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+9
-14
@@ -1,30 +1,25 @@
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class HandleRiotDoNothingCommandSelector : CommandSelector
|
||||
{
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.HandleRiotDoNothingAvailableCommand;
|
||||
namespace eagle {
|
||||
public class HandleRiotDoNothingCommandSelector : CommandSelector {
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.HandleRiotDoNothingAvailableCommand;
|
||||
|
||||
public override string HeaderString => "Ignore Imminent Riot";
|
||||
|
||||
public override string CommitButtonString => "Commit Ignore";
|
||||
|
||||
private HandleRiotDoNothingAvailableCommand HandleRiotDoNothingCommand => _availableCommand.HandleRiotDoNothingAvailableCommand;
|
||||
private HandleRiotDoNothingAvailableCommand HandleRiotDoNothingCommand =>
|
||||
_availableCommand.HandleRiotDoNothingAvailableCommand;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
HandleRiotDoNothingSelectedCommand = new HandleRiotDoNothingSelectedCommand()
|
||||
};
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
}
|
||||
protected override void SetUpUI() {}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+23
-50
@@ -3,12 +3,10 @@ using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class HandleRiotGiveCommandSelector : CommandSelector
|
||||
{
|
||||
public class HandleRiotGiveCommandSelector : CommandSelector {
|
||||
public Toggle foodToggle;
|
||||
public Toggle goldToggle;
|
||||
|
||||
@@ -17,39 +15,33 @@ namespace eagle
|
||||
public Slider goldTakenSlider;
|
||||
public TMP_Text goldTakenLabel;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.HandleRiotGiveAvailableCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.HandleRiotGiveAvailableCommand;
|
||||
|
||||
public override string HeaderString => "Give to Populace";
|
||||
|
||||
public override string CommitButtonString => "Commit Gift";
|
||||
|
||||
private HandleRiotGiveSelectedCommand SpecializedCommand()
|
||||
{
|
||||
private HandleRiotGiveSelectedCommand SpecializedCommand() {
|
||||
var spc = new HandleRiotGiveSelectedCommand();
|
||||
if (foodToggle.isOn)
|
||||
{
|
||||
if (foodToggle.isOn) {
|
||||
spc.FoodAmount = (int)foodTakenSlider.value;
|
||||
}
|
||||
else if (goldToggle.isOn)
|
||||
{
|
||||
} else if (goldToggle.isOn) {
|
||||
spc.GoldAmount = (int)goldTakenSlider.value;
|
||||
}
|
||||
|
||||
return spc;
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
HandleRiotGiveSelectedCommand = SpecializedCommand()
|
||||
};
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand { HandleRiotGiveSelectedCommand = SpecializedCommand() };
|
||||
|
||||
private HandleRiotGiveAvailableCommand HandleRiotCommand => _availableCommand.HandleRiotGiveAvailableCommand;
|
||||
private HandleRiotGiveAvailableCommand HandleRiotCommand =>
|
||||
_availableCommand.HandleRiotGiveAvailableCommand;
|
||||
private ProvinceId ActingProvinceId => HandleRiotCommand.ActingProvinceId;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
if (HandleRiotCommand.GoldAvailable > 0)
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
if (HandleRiotCommand.GoldAvailable > 0) {
|
||||
goldTakenSlider.maxValue = HandleRiotCommand.GoldAvailable;
|
||||
goldTakenSlider.minValue = 1;
|
||||
goldTakenSlider.value = HandleRiotCommand.GoldAvailable;
|
||||
@@ -58,15 +50,12 @@ namespace eagle
|
||||
goldToggle.gameObject.SetActive(true);
|
||||
foodToggle.isOn = false;
|
||||
goldToggle.isOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
goldToggle.enabled = false;
|
||||
goldToggle.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (HandleRiotCommand.FoodAvailable > 0)
|
||||
{
|
||||
if (HandleRiotCommand.FoodAvailable > 0) {
|
||||
foodTakenSlider.maxValue = HandleRiotCommand.FoodAvailable;
|
||||
foodTakenSlider.minValue = 1;
|
||||
foodTakenSlider.value = HandleRiotCommand.FoodAvailable;
|
||||
@@ -75,57 +64,41 @@ namespace eagle
|
||||
foodToggle.gameObject.SetActive(true);
|
||||
goldToggle.isOn = false;
|
||||
foodToggle.isOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
foodToggle.enabled = false;
|
||||
foodToggle.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
void Start() {}
|
||||
|
||||
}
|
||||
public void FoodSliderMoved(float value) { foodTakenLabel.text = $"{(int)value}"; }
|
||||
|
||||
public void GoldSliderMoved(float value) { goldTakenLabel.text = $"{(int)value}"; }
|
||||
|
||||
public void FoodSliderMoved(float value)
|
||||
{
|
||||
foodTakenLabel.text = $"{(int)value}";
|
||||
}
|
||||
|
||||
public void GoldSliderMoved(float value)
|
||||
{
|
||||
goldTakenLabel.text = $"{(int)value}";
|
||||
}
|
||||
|
||||
public void FoodToggleSelected()
|
||||
{
|
||||
public void FoodToggleSelected() {
|
||||
foodTakenSlider.gameObject.SetActive(true);
|
||||
foodTakenLabel.gameObject.SetActive(true);
|
||||
goldTakenSlider.gameObject.SetActive(false);
|
||||
goldTakenLabel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void GoldToggleSelected()
|
||||
{
|
||||
public void GoldToggleSelected() {
|
||||
foodTakenSlider.gameObject.SetActive(false);
|
||||
foodTakenLabel.gameObject.SetActive(false);
|
||||
goldTakenSlider.gameObject.SetActive(true);
|
||||
goldTakenLabel.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void CrackDownToggleSelected()
|
||||
{
|
||||
public void CrackDownToggleSelected() {
|
||||
foodTakenSlider.gameObject.SetActive(false);
|
||||
foodTakenLabel.gameObject.SetActive(false);
|
||||
goldTakenSlider.gameObject.SetActive(false);
|
||||
goldTakenLabel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void NothingToggleSelected()
|
||||
{
|
||||
public void NothingToggleSelected() {
|
||||
foodTakenSlider.gameObject.SetActive(false);
|
||||
foodTakenLabel.gameObject.SetActive(false);
|
||||
goldTakenSlider.gameObject.SetActive(false);
|
||||
|
||||
+53
-55
@@ -6,13 +6,11 @@ using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
using HeroId = System.Int32;
|
||||
|
||||
public class HeroGiftCommandSelector : CommandSelector
|
||||
{
|
||||
public class HeroGiftCommandSelector : CommandSelector {
|
||||
public TMP_Dropdown provinceDropdown;
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public Slider goldSlider;
|
||||
@@ -21,51 +19,62 @@ namespace eagle
|
||||
private HeroGiftAvailableCommand HeroGiftCommand => _availableCommand.HeroGiftCommand;
|
||||
private ProvinceId ActingProvinceId => HeroGiftCommand.ActingProvinceId;
|
||||
|
||||
private ProvinceId? FilterProvince => provinceDropdown.value == 0 ? null : (ProvinceId?)HeroGiftCommand.EligibleGifts.GroupBy(eg => eg.RecipientProvinceId).ToList()[provinceDropdown.value - 1].Key;
|
||||
private ProvinceId? FilterProvince =>
|
||||
provinceDropdown.value == 0 ? null
|
||||
: (ProvinceId?)HeroGiftCommand.EligibleGifts
|
||||
.GroupBy(eg => eg.RecipientProvinceId)
|
||||
.ToList()[provinceDropdown.value - 1]
|
||||
.Key;
|
||||
|
||||
private List<EligibleGift> FilteredEligibleGifts => FilterProvince == null ? HeroGiftCommand.EligibleGifts.ToList() : HeroGiftCommand
|
||||
.EligibleGifts
|
||||
private List<EligibleGift> FilteredEligibleGifts =>
|
||||
FilterProvince == null
|
||||
? HeroGiftCommand.EligibleGifts.ToList()
|
||||
: HeroGiftCommand.EligibleGifts
|
||||
.Where(eg => eg.RecipientProvinceId == FilterProvince.Value)
|
||||
.ToList();
|
||||
|
||||
private List<HeroId> AvailableHeroIds => FilteredEligibleGifts
|
||||
.Select(eg => eg.RecipientHeroId)
|
||||
.ToList();
|
||||
private List<HeroId> AvailableHeroIds =>
|
||||
FilteredEligibleGifts.Select(eg => eg.RecipientHeroId).ToList();
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private int AvailableGold => HeroGiftCommand.EligibleGifts.ToList().Find(eg => eg.RecipientHeroId == SelectedHeroId).GoldAvailable;
|
||||
private int AvailableGold => HeroGiftCommand.EligibleGifts.ToList()
|
||||
.Find(eg => eg.RecipientHeroId == SelectedHeroId)
|
||||
.GoldAvailable;
|
||||
private int SelectedGoldAmount => (int)goldSlider.value;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.HeroGiftCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.HeroGiftCommand;
|
||||
public override string HeaderString => "Give to Hero";
|
||||
public override string CommitButtonString => "Commit Gift";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => HeroGiftCommand.EligibleGifts.Where(eg => eg.RecipientHeroId == heroId).Count() > 0;
|
||||
public override void AddTargetedHero(HeroId heroId)
|
||||
{
|
||||
var eligibleGift = HeroGiftCommand.EligibleGifts.Where(eg => eg.RecipientHeroId == heroId).First();
|
||||
if (TargetedProvince.HasValue && TargetedProvince != eligibleGift.RecipientProvinceId) TargetedProvince = null;
|
||||
else heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
HeroGiftCommand.EligibleGifts.Where(eg => eg.RecipientHeroId == heroId).Count() > 0;
|
||||
public override void AddTargetedHero(HeroId heroId) {
|
||||
var eligibleGift =
|
||||
HeroGiftCommand.EligibleGifts.Where(eg => eg.RecipientHeroId == heroId).First();
|
||||
if (TargetedProvince.HasValue && TargetedProvince != eligibleGift.RecipientProvinceId)
|
||||
TargetedProvince = null;
|
||||
else
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
}
|
||||
|
||||
public override bool EnableCommitButton => SelectedGoldAmount > 0;
|
||||
public override string DisabledCommitButtonReason => "Must send some gold";
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => FilterProvince;
|
||||
set
|
||||
{
|
||||
set {
|
||||
var newIndex = 0;
|
||||
if (value is ProvinceId pid)
|
||||
{
|
||||
var index = HeroGiftCommand.EligibleGifts.GroupBy(eg => eg.RecipientProvinceId).Select(x => x.Key).ToList().IndexOf(pid);
|
||||
if (value is ProvinceId pid) {
|
||||
var index = HeroGiftCommand.EligibleGifts.GroupBy(eg => eg.RecipientProvinceId)
|
||||
.Select(x => x.Key)
|
||||
.ToList()
|
||||
.IndexOf(pid);
|
||||
if (index != -1) newIndex = index + 1;
|
||||
}
|
||||
|
||||
if (newIndex != provinceDropdown.value)
|
||||
{
|
||||
if (newIndex != provinceDropdown.value) {
|
||||
provinceDropdown.value = newIndex;
|
||||
SetUpHeroDropdown();
|
||||
}
|
||||
@@ -74,16 +83,17 @@ namespace eagle
|
||||
public override bool WarnOnCommitButton => false;
|
||||
public override string CommitWarningText => null;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
void Awake() {
|
||||
heroDropdownController.ConditionAccessor = hero => hero.Loyalty;
|
||||
heroDropdownController.ConditionName = "LOY";
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
provinceDropdown.ClearOptions();
|
||||
var availableProvinces = HeroGiftCommand.EligibleGifts.GroupBy(eg => eg.RecipientProvinceId).Select(x => x.Key).ToList();
|
||||
var availableProvinces =
|
||||
HeroGiftCommand.EligibleGifts.GroupBy(eg => eg.RecipientProvinceId)
|
||||
.Select(x => x.Key)
|
||||
.ToList();
|
||||
var optionsList = new List<string> { "All" };
|
||||
optionsList.AddRange(availableProvinces.Select(pid => _model.Provinces[pid].Name));
|
||||
provinceDropdown.AddOptions(optionsList);
|
||||
@@ -96,44 +106,32 @@ namespace eagle
|
||||
goldSlider.maxValue = AvailableGold;
|
||||
}
|
||||
|
||||
public void SetUpHeroDropdown()
|
||||
{
|
||||
var heroes = AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
public void SetUpHeroDropdown() {
|
||||
var heroes = AvailableHeroIds.Select(hid => _model.Heroes[hid]).ToList();
|
||||
|
||||
heroDropdownController.AvailableHeroes = heroes;
|
||||
|
||||
HeroView minLoyaltyHero = null;
|
||||
foreach (HeroView hero in heroes)
|
||||
{
|
||||
if (minLoyaltyHero == null || hero.Loyalty.Stat < minLoyaltyHero.Loyalty.Stat)
|
||||
{
|
||||
foreach (HeroView hero in heroes) {
|
||||
if (minLoyaltyHero == null || hero.Loyalty.Stat < minLoyaltyHero.Loyalty.Stat) {
|
||||
minLoyaltyHero = hero;
|
||||
}
|
||||
}
|
||||
heroDropdownController.SelectedHeroId = minLoyaltyHero.Id;
|
||||
}
|
||||
|
||||
public void HeroSelected()
|
||||
{
|
||||
public void HeroSelected() {
|
||||
goldSlider.maxValue = AvailableGold;
|
||||
goldSlider.value = Math.Min(goldSlider.value, AvailableGold);
|
||||
}
|
||||
|
||||
public void GoldSliderMoved(float value)
|
||||
{
|
||||
goldGivenLabel.text = ((int)value).ToString();
|
||||
}
|
||||
public void GoldSliderMoved(float value) { goldGivenLabel.text = ((int)value).ToString(); }
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
HeroGiftCommand = new HeroGiftSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var cmd = new SelectedCommand {
|
||||
HeroGiftCommand =
|
||||
new HeroGiftSelectedCommand {
|
||||
RecipientHeroId = SelectedHeroId,
|
||||
Amount = SelectedGoldAmount
|
||||
}
|
||||
|
||||
+48
-67
@@ -8,13 +8,11 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
using HeroId = Int32;
|
||||
|
||||
public class ImproveCommandSelector : CommandSelector
|
||||
{
|
||||
public class ImproveCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public TMP_Dropdown typeDropdown;
|
||||
public Toggle lockToggle;
|
||||
@@ -24,32 +22,32 @@ namespace eagle
|
||||
private int SelectedTypeIndex => typeDropdown.value;
|
||||
private ImproveAvailableCommand ImproveAvailableCommand => _availableCommand.ImproveCommand;
|
||||
private ProvinceId ActingProvinceId => ImproveAvailableCommand.ActingProvinceId;
|
||||
private ImprovementType SelectedType => ImproveAvailableCommand.AvailableTypes[SelectedTypeIndex];
|
||||
private ImprovementType SelectedType =>
|
||||
ImproveAvailableCommand.AvailableTypes[SelectedTypeIndex];
|
||||
|
||||
private Dictionary<ProvinceId, ImprovementType> lockedTypes = new Dictionary<ProvinceId, ImprovementType>();
|
||||
private Dictionary<ProvinceId, ImprovementType> lockedTypes =
|
||||
new Dictionary<ProvinceId, ImprovementType>();
|
||||
|
||||
private double ImprovementValueForType(ImprovementType type)
|
||||
{
|
||||
private double ImprovementValueForType(ImprovementType type) {
|
||||
var province = _model.Provinces[ActingProvinceId];
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case ImprovementType.Agriculture: return province.FullInfo.Agriculture;
|
||||
case ImprovementType.Economy: return province.FullInfo.Economy;
|
||||
case ImprovementType.Infrastructure: return province.FullInfo.Infrastructure;
|
||||
case ImprovementType.Devastation: return province.FullInfo.EconomyDevastation + province.FullInfo.AgricultureDevastation + province.FullInfo.InfrastructureDevastation;
|
||||
case ImprovementType.Devastation:
|
||||
return province.FullInfo.EconomyDevastation +
|
||||
province.FullInfo.AgricultureDevastation +
|
||||
province.FullInfo.InfrastructureDevastation;
|
||||
default: throw new InvalidOperationException($"unknown type {type}");
|
||||
}
|
||||
}
|
||||
|
||||
private int MinimumImprovementIndex(ProvinceView province)
|
||||
{
|
||||
private int MinimumImprovementIndex(ProvinceView province) {
|
||||
var minIndex = 0;
|
||||
double minValue = ImprovementValueForType(ImproveAvailableCommand.AvailableTypes[0]);
|
||||
for (int i = 1; i < ImproveAvailableCommand.AvailableTypes.Count; i++)
|
||||
{
|
||||
for (int i = 1; i < ImproveAvailableCommand.AvailableTypes.Count; i++) {
|
||||
double thisVal = ImprovementValueForType(ImproveAvailableCommand.AvailableTypes[i]);
|
||||
if (thisVal < minValue)
|
||||
{
|
||||
if (thisVal < minValue) {
|
||||
minIndex = i;
|
||||
minValue = thisVal;
|
||||
}
|
||||
@@ -57,111 +55,94 @@ namespace eagle
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
var province = _model.Provinces[ImproveAvailableCommand.ActingProvinceId];
|
||||
var improveCommand = ImproveAvailableCommand;
|
||||
|
||||
typeDropdown.ClearOptions();
|
||||
|
||||
orderedHeroes = ImproveAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
orderedHeroes = ImproveAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id])
|
||||
.ToList();
|
||||
heroDropdownController.AvailableHeroes = orderedHeroes;
|
||||
|
||||
heroDropdownController.SelectedHeroId = improveCommand.RecommendedHeroId;
|
||||
|
||||
typeDropdown.AddOptions(improveCommand.AvailableTypes.Select(DropdownStringForType).ToList());
|
||||
typeDropdown.AddOptions(
|
||||
improveCommand.AvailableTypes.Select(DropdownStringForType).ToList());
|
||||
|
||||
var devastationIndex = improveCommand.AvailableTypes.IndexOf(ImprovementType.Devastation);
|
||||
if (devastationIndex == -1)
|
||||
{
|
||||
var devastationIndex =
|
||||
improveCommand.AvailableTypes.IndexOf(ImprovementType.Devastation);
|
||||
if (devastationIndex == -1) {
|
||||
typeDropdown.value = MinimumImprovementIndex(province);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
typeDropdown.value = devastationIndex;
|
||||
}
|
||||
|
||||
typeDropdown.interactable = true;
|
||||
|
||||
if (lockedTypes.ContainsKey(province.Id))
|
||||
{
|
||||
if (lockedTypes.ContainsKey(province.Id)) {
|
||||
var lockedType = lockedTypes[province.Id];
|
||||
var lockedTypeIndex = improveCommand.AvailableTypes.IndexOf(lockedType);
|
||||
if (lockedTypeIndex > -1)
|
||||
{
|
||||
if (lockedTypeIndex > -1) {
|
||||
typeDropdown.value = lockedTypeIndex;
|
||||
lockToggle.isOn = true;
|
||||
typeDropdown.interactable = false;
|
||||
} else {
|
||||
lockToggle.isOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lockToggle.isOn = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lockToggle.isOn = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ImproveCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ImproveCommand;
|
||||
public override string HeaderString => "Improve Province";
|
||||
public override string CommitButtonString => "Commit Improvement";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { heroDropdownController.SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId)
|
||||
{
|
||||
public override List<HeroId> TargetedHeroIds =>
|
||||
new List<HeroId> { heroDropdownController.SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) {
|
||||
var index = orderedHeroes.FindIndex(h => h.Id == heroId);
|
||||
return index != -1;
|
||||
}
|
||||
|
||||
public override void AddTargetedHero(int heroId)
|
||||
{
|
||||
public override void AddTargetedHero(int heroId) {
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
}
|
||||
|
||||
public void LockToggled(bool isLocked)
|
||||
{
|
||||
if (isLocked)
|
||||
{
|
||||
public void LockToggled(bool isLocked) {
|
||||
if (isLocked) {
|
||||
lockedTypes[ImproveAvailableCommand.ActingProvinceId] = SelectedType;
|
||||
typeDropdown.interactable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lockedTypes.Remove(ActingProvinceId);
|
||||
typeDropdown.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ImproveCommand = new ImproveSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ImproveCommand =
|
||||
new ImproveSelectedCommand {
|
||||
ImprovementType = SelectedType,
|
||||
ActingHeroId = heroDropdownController.SelectedHeroId
|
||||
}
|
||||
};
|
||||
|
||||
private string DropdownStringForType(ImprovementType type)
|
||||
{
|
||||
private string DropdownStringForType(ImprovementType type) {
|
||||
return $"{type} ({RoundedNonzeroStat(ImprovementValueForType(type))})";
|
||||
}
|
||||
|
||||
private string RoundedNonzeroStat(double stat)
|
||||
{
|
||||
private string RoundedNonzeroStat(double stat) {
|
||||
var rounded = Math.Max(1, Math.Round(stat, MidpointRounding.AwayFromZero));
|
||||
return rounded.ToString();
|
||||
}
|
||||
|
||||
private string DropdownStringForHero(HeroView hero)
|
||||
{
|
||||
return $"{hero.Name}: "
|
||||
+ $"{RoundedNonzeroStat(hero.Strength)} STR, "
|
||||
+ $"{RoundedNonzeroStat(hero.Agility)} AGI, "
|
||||
+ $"{GUIUtils.ConditionString(hero.Vigor, true)} / {RoundedNonzeroStat(hero.Constitution)} VIG"
|
||||
+ ((hero.Profession == Profession.Engineer) ? " (Engineer)" : "");
|
||||
private string DropdownStringForHero(HeroView hero) {
|
||||
return $"{hero.Name}: " + $"{RoundedNonzeroStat(hero.Strength)} STR, " +
|
||||
$"{RoundedNonzeroStat(hero.Agility)} AGI, " +
|
||||
$"{GUIUtils.ConditionString(hero.Vigor, true)} / {RoundedNonzeroStat(hero.Constitution)} VIG" +
|
||||
((hero.Profession == Profession.Engineer) ? " (Engineer)" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
-45
@@ -8,12 +8,10 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class IssueOrdersCommandSelector : CommandSelector
|
||||
{
|
||||
public class IssueOrdersCommandSelector : CommandSelector {
|
||||
IList<ProvinceOrderType> availableOrderTypes;
|
||||
Dictionary<ProvinceId, ProvinceOrderType> currentOrders;
|
||||
List<ProvinceOrders> newOrders;
|
||||
@@ -27,14 +25,13 @@ namespace eagle
|
||||
public GameObject scrollContent;
|
||||
public GameObject provinceOrdersRowPrefab;
|
||||
|
||||
private IssueOrdersAvailableCommand IssueOrdersAvailableCommand => _availableCommand.IssueOrdersCommand;
|
||||
private IssueOrdersAvailableCommand IssueOrdersAvailableCommand =>
|
||||
_availableCommand.IssueOrdersCommand;
|
||||
private ProvinceId ActingProvinceId => IssueOrdersAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => SelectedFocusProvince;
|
||||
set
|
||||
{
|
||||
set {
|
||||
var index = availableFocusProvinces.IndexOf(value);
|
||||
if (index == -1) return;
|
||||
|
||||
@@ -42,53 +39,58 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProvinceId?> GetAvailableFocusProvinces()
|
||||
{
|
||||
private List<ProvinceId?> GetAvailableFocusProvinces() {
|
||||
var pids = _model.ProvincesForFaction(_model.PlayerId.Value);
|
||||
var optionals = new List<ProvinceId?> { null };
|
||||
optionals.AddRange(pids.Select(x => (ProvinceId?)x));
|
||||
return optionals;
|
||||
}
|
||||
|
||||
private string OptionalProvinceName(ProvinceId? pid)
|
||||
{
|
||||
private string OptionalProvinceName(ProvinceId? pid) {
|
||||
if (pid.HasValue) return _model.Provinces[pid.Value].Name;
|
||||
else return "None";
|
||||
else
|
||||
return "None";
|
||||
}
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.IssueOrdersCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.IssueOrdersCommand;
|
||||
override public string HeaderString => "Issue Orders";
|
||||
override public string CommitButtonString => "Commit Orders";
|
||||
|
||||
override public bool EnableCommitButton => (newOrders.Any(x => x.Orders != currentOrders[x.ProvinceId])) || (SelectedFocusProvince != startingFocusProvince);
|
||||
override public bool EnableCommitButton =>
|
||||
(newOrders.Any(x => x.Orders != currentOrders[x.ProvinceId])) ||
|
||||
(SelectedFocusProvince != startingFocusProvince);
|
||||
public override string DisabledCommitButtonReason => "No province orders have changed";
|
||||
|
||||
override protected void SetUpUI()
|
||||
{
|
||||
override protected void SetUpUI() {
|
||||
availableOrderTypes = IssueOrdersAvailableCommand.AvailableOrders;
|
||||
currentOrders = IssueOrdersAvailableCommand.CurrentOrders.ToDictionary(x => x.ProvinceId, x => x.Orders);
|
||||
currentOrders = IssueOrdersAvailableCommand.CurrentOrders.ToDictionary(
|
||||
x => x.ProvinceId,
|
||||
x => x.Orders);
|
||||
|
||||
newOrders = IssueOrdersAvailableCommand.CurrentOrders.ToList();
|
||||
newOrders.Sort((x, y) => _model.Provinces[x.ProvinceId].Name.CompareTo(_model.Provinces[y.ProvinceId].Name));
|
||||
newOrders.Sort(
|
||||
(x, y) => _model.Provinces[x.ProvinceId].Name.CompareTo(
|
||||
_model.Provinces[y.ProvinceId].Name));
|
||||
|
||||
provinceIds = newOrders.Select(x => x.ProvinceId).ToList();
|
||||
|
||||
foreach (Transform row in scrollContent.transform)
|
||||
{
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
foreach (Transform row in scrollContent.transform) { Destroy(row.gameObject); }
|
||||
|
||||
var parentTransform = scrollContent.transform;
|
||||
|
||||
var oddColor = provinceOrdersRowPrefab.GetComponent<UnityEngine.UI.Image>().color;
|
||||
oddColor.a = 0;
|
||||
|
||||
for (int i = 0; i < provinceIds.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < provinceIds.Count; i++) {
|
||||
var pid = provinceIds[i];
|
||||
var province = _model.Provinces[pid];
|
||||
|
||||
var newRow = Instantiate(provinceOrdersRowPrefab, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), parentTransform);
|
||||
var newRow = Instantiate(
|
||||
provinceOrdersRowPrefab,
|
||||
new Vector3(0, 0, 0),
|
||||
new Quaternion(0, 0, 0, 0),
|
||||
parentTransform);
|
||||
|
||||
// FIXME: I don't know why this reset of the z-position is necessary
|
||||
var position = newRow.GetComponent<RectTransform>().anchoredPosition3D;
|
||||
@@ -103,43 +105,39 @@ namespace eagle
|
||||
|
||||
var ordersDropdown = newRow.GetComponentInChildren<TMP_Dropdown>();
|
||||
ordersDropdown.ClearOptions();
|
||||
ordersDropdown.AddOptions(availableOrderTypes.Select(tp => DisplayNames.ProvinceOrderTypeNames[tp]).ToList());
|
||||
ordersDropdown.AddOptions(
|
||||
availableOrderTypes.Select(tp => DisplayNames.ProvinceOrderTypeNames[tp])
|
||||
.ToList());
|
||||
ordersDropdown.value = availableOrderTypes.IndexOf(currentOrders[pid]);
|
||||
int index = i;
|
||||
ordersDropdown.onValueChanged.AddListener(newValue => ProvinceOrdersValueChanged(index, newValue));
|
||||
ordersDropdown.onValueChanged.AddListener(
|
||||
newValue => ProvinceOrdersValueChanged(index, newValue));
|
||||
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor;
|
||||
}
|
||||
if (i % 2 == 1) { newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor; }
|
||||
}
|
||||
|
||||
startingFocusProvince = _model.MaybeDestroyedFaction(_model.PlayerId.Value).FocusProvinceId;
|
||||
startingFocusProvince =
|
||||
_model.MaybeDestroyedFaction(_model.PlayerId.Value).FocusProvinceId;
|
||||
availableFocusProvinces = GetAvailableFocusProvinces();
|
||||
availableFocusProvinceNames = availableFocusProvinces.Select(OptionalProvinceName).ToList();
|
||||
availableFocusProvinceNames =
|
||||
availableFocusProvinces.Select(OptionalProvinceName).ToList();
|
||||
|
||||
focusDropdown.ClearOptions();
|
||||
focusDropdown.AddOptions(availableFocusProvinceNames);
|
||||
focusDropdown.value = availableFocusProvinces.IndexOf(startingFocusProvince);
|
||||
}
|
||||
|
||||
override public SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
override public SelectedCommand Command {
|
||||
get {
|
||||
var sentOrders = newOrders.Where(x => x.Orders != currentOrders[x.ProvinceId]);
|
||||
var ordersCommand = new IssueOrdersSelectedCommand();
|
||||
ordersCommand.NewOrders.Add(sentOrders);
|
||||
ordersCommand.NewFocusProvince = SelectedFocusProvince;
|
||||
return new SelectedCommand
|
||||
{
|
||||
IssueOrdersCommand = ordersCommand
|
||||
};
|
||||
return new SelectedCommand { IssueOrdersCommand = ordersCommand };
|
||||
}
|
||||
}
|
||||
|
||||
public void ProvinceOrdersValueChanged(int index, Int32 newValue)
|
||||
{
|
||||
public void ProvinceOrdersValueChanged(int index, Int32 newValue) {
|
||||
newOrders[index].Orders = availableOrderTypes[newValue];
|
||||
}
|
||||
}
|
||||
|
||||
+50
-21
@@ -31,37 +31,45 @@ namespace eagle {
|
||||
|
||||
public HeroView SelectedHero => SelectedPrisonerToManage.Prisoner.Hero;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ManagePrisonerCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ManagePrisonerCommand;
|
||||
public override string HeaderString => "Manage Prisoners";
|
||||
public override string CommitButtonString => $"Commit {DisplayNames.PrisonerManagementTypeName(SelectedOption)}";
|
||||
public override string CommitButtonString =>
|
||||
$"Commit {DisplayNames.PrisonerManagementTypeName(SelectedOption)}";
|
||||
|
||||
private int _selectedHeroIndex;
|
||||
private PrisonerToManage SelectedPrisonerToManage => ManagePrisonersCommand.Prisoners[_selectedHeroIndex];
|
||||
private PrisonerToManage SelectedPrisonerToManage =>
|
||||
ManagePrisonersCommand.Prisoners[_selectedHeroIndex];
|
||||
|
||||
private ManagePrisonersAvailableCommand ManagePrisonersCommand => _availableCommand.ManagePrisonerCommand;
|
||||
private ManagePrisonersAvailableCommand ManagePrisonersCommand =>
|
||||
_availableCommand.ManagePrisonerCommand;
|
||||
private ProvinceId ActingProvinceId => ManagePrisonersCommand.ActingProvinceId;
|
||||
|
||||
public override bool WarnOnCommitButton => false;
|
||||
public override string CommitWarningText => $"This will create a treaty with {_model.FactionName(SelectedHero.FactionId.Value)}";
|
||||
public override string CommitWarningText =>
|
||||
$"This will create a treaty with {_model.FactionName(SelectedHero.FactionId.Value)}";
|
||||
|
||||
private PrisonerManagementOption SelectedOption {
|
||||
get {
|
||||
if (ExecuteToggle.isOn)
|
||||
return SelectedPrisonerToManage
|
||||
.AvailableOptions
|
||||
.First(opt => opt.SealedValueCase == PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
else throw new ArgumentOutOfRangeException("Unknown prisoner management option");
|
||||
return SelectedPrisonerToManage.AvailableOptions.First(
|
||||
opt => opt.SealedValueCase ==
|
||||
PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
else
|
||||
throw new ArgumentOutOfRangeException("Unknown prisoner management option");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetUpUI() {
|
||||
if (_selectedHeroIndex >= ManagePrisonersCommand.Prisoners.Count) _selectedHeroIndex = 0;
|
||||
if (_selectedHeroIndex >= ManagePrisonersCommand.Prisoners.Count)
|
||||
_selectedHeroIndex = 0;
|
||||
NextHeroButton.gameObject.SetActive(ManagePrisonersCommand.Prisoners.Count > 1);
|
||||
DisplaySelectedHero();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ManagePrisonersCommand = new ManagePrisonersSelectedCommand {
|
||||
ManagePrisonersCommand =
|
||||
new ManagePrisonersSelectedCommand {
|
||||
PrisonerHeroId = SelectedHero.Id,
|
||||
ChosenOption = SelectedOption
|
||||
}
|
||||
@@ -83,15 +91,33 @@ namespace eagle {
|
||||
|
||||
// The order here is important: the last available toggle in this list
|
||||
// will be on by default
|
||||
ConditionallyEnable(ExecuteToggle, ExecuteIcon, PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
ConditionallyEnable(ExileToggle, ExileIcon, PrisonerManagementOption.SealedValueOneofCase.Exile);
|
||||
ConditionallyEnable(ReturnToggle, ReturnIcon, PrisonerManagementOption.SealedValueOneofCase.Return);
|
||||
ConditionallyEnable(MoveToggle, MoveIcon, PrisonerManagementOption.SealedValueOneofCase.Move);
|
||||
ConditionallyEnable(ReleaseToggle, ReleaseIcon, PrisonerManagementOption.SealedValueOneofCase.Release);
|
||||
ConditionallyEnable(
|
||||
ExecuteToggle,
|
||||
ExecuteIcon,
|
||||
PrisonerManagementOption.SealedValueOneofCase.Execute);
|
||||
ConditionallyEnable(
|
||||
ExileToggle,
|
||||
ExileIcon,
|
||||
PrisonerManagementOption.SealedValueOneofCase.Exile);
|
||||
ConditionallyEnable(
|
||||
ReturnToggle,
|
||||
ReturnIcon,
|
||||
PrisonerManagementOption.SealedValueOneofCase.Return);
|
||||
ConditionallyEnable(
|
||||
MoveToggle,
|
||||
MoveIcon,
|
||||
PrisonerManagementOption.SealedValueOneofCase.Move);
|
||||
ConditionallyEnable(
|
||||
ReleaseToggle,
|
||||
ReleaseIcon,
|
||||
PrisonerManagementOption.SealedValueOneofCase.Release);
|
||||
}
|
||||
|
||||
private bool ConditionallyEnable(Toggle toggle, PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
bool enable = SelectedPrisonerToManage.AvailableOptions.Any(opt => opt.SealedValueCase == option);
|
||||
private bool ConditionallyEnable(
|
||||
Toggle toggle,
|
||||
PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
bool enable = SelectedPrisonerToManage.AvailableOptions.Any(
|
||||
opt => opt.SealedValueCase == option);
|
||||
toggle.gameObject.SetActive(enable);
|
||||
|
||||
if (enable) {
|
||||
@@ -102,13 +128,16 @@ namespace eagle {
|
||||
ReturnToggle.isOn = false;
|
||||
|
||||
toggle.isOn = true;
|
||||
}
|
||||
else toggle.isOn = false;
|
||||
} else
|
||||
toggle.isOn = false;
|
||||
|
||||
return enable;
|
||||
}
|
||||
|
||||
private void ConditionallyEnable(Toggle toggle, RawImage img, PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
private void ConditionallyEnable(
|
||||
Toggle toggle,
|
||||
RawImage img,
|
||||
PrisonerManagementOption.SealedValueOneofCase option) {
|
||||
bool enable = ConditionallyEnable(toggle, option);
|
||||
|
||||
Color color = img.color;
|
||||
|
||||
+127
-142
@@ -7,30 +7,24 @@ using UnityEngine.UI;
|
||||
using EagleGUIUtils;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using PlayerId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
using BattalionId = System.Int32;
|
||||
using HeroId = System.Int32;
|
||||
using static Net.Eagle0.Eagle.Api.Command.Util.SuitableBattalions.Types;
|
||||
|
||||
struct Supplies
|
||||
{
|
||||
struct Supplies {
|
||||
public int gold;
|
||||
public int food;
|
||||
}
|
||||
|
||||
public class MarchCommandSelector : CommandSelector
|
||||
{
|
||||
public class MarchCommandSelector : CommandSelector {
|
||||
private int SelectedOriginProvinceIndex => fromDropdown.value;
|
||||
private int SelectedDestinationProvinceIndex => toDropdown.value;
|
||||
private List<CombatUnit> SelectedActingUnits => unitSelector.SelectedActingUnits;
|
||||
private Supplies SelectedSupplies => new Supplies
|
||||
{
|
||||
gold = SelectedGold,
|
||||
food = SelectedFood
|
||||
};
|
||||
private Supplies SelectedSupplies =>
|
||||
new Supplies { gold = SelectedGold, food = SelectedFood };
|
||||
private int SelectedGold => (int)goldSlider.value;
|
||||
private int SelectedFood => (int)foodSlider.value;
|
||||
|
||||
@@ -48,79 +42,93 @@ namespace eagle
|
||||
private int recommendedFood;
|
||||
private int recommendedGold;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.MarchCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.MarchCommand;
|
||||
public override string HeaderString => "March";
|
||||
public override string CommitButtonString => "Commit March";
|
||||
|
||||
private MarchAvailableCommand MarchAvailableCommand => _availableCommand.MarchCommand;
|
||||
private ProvinceId ActingProvinceId => MarchAvailableCommand.ActingProvinceId;
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => unitSelector.SelectedIds.Where(u => u.heroId.HasValue).Select(u => u.heroId.Value).ToList();
|
||||
public override bool HeroIsTargetable(HeroId heroId) => unitSelector.HeroIsTargetable(heroId);
|
||||
public override List<HeroId> TargetedHeroIds =>
|
||||
unitSelector.SelectedIds.Where(u => u.heroId.HasValue)
|
||||
.Select(u => u.heroId.Value)
|
||||
.ToList();
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
unitSelector.HeroIsTargetable(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => unitSelector.AddTargetedHero(heroId);
|
||||
public override void RemoveTargetedHero(HeroId heroId) => unitSelector.RemoveTargetedHero(heroId);
|
||||
public override void RemoveTargetedHero(HeroId heroId) =>
|
||||
unitSelector.RemoveTargetedHero(heroId);
|
||||
|
||||
public override List<BattalionId> TargetedBattalionIds => unitSelector.SelectedIds.Where(u => u.battalion != null).Select(u => u.battalion.Id).ToList();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) => unitSelector.BattalionIsTargetable(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) => unitSelector.AddTargetedBattalion(bid);
|
||||
public override void RemoveTargetedBattalion(BattalionId bid) => unitSelector.RemoveTargetedBattalion(bid);
|
||||
public override List<BattalionId> TargetedBattalionIds =>
|
||||
unitSelector.SelectedIds.Where(u => u.battalion != null)
|
||||
.Select(u => u.battalion.Id)
|
||||
.ToList();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) =>
|
||||
unitSelector.BattalionIsTargetable(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) =>
|
||||
unitSelector.AddTargetedBattalion(bid);
|
||||
public override void RemoveTargetedBattalion(BattalionId bid) =>
|
||||
unitSelector.RemoveTargetedBattalion(bid);
|
||||
|
||||
private List<MarchCommandFromOneProvince> sortedOneProvinceCommands;
|
||||
private List<ProvinceId> sortedDestinationProvinceIds;
|
||||
|
||||
private ProvinceView OriginProvince => _model.Provinces[SelectedOneProvinceCommand.OriginProvinceId];
|
||||
private ProvinceId DestinationProvinceId => sortedDestinationProvinceIds[SelectedDestinationProvinceIndex];
|
||||
private ProvinceView OriginProvince =>
|
||||
_model.Provinces[SelectedOneProvinceCommand.OriginProvinceId];
|
||||
private ProvinceId DestinationProvinceId =>
|
||||
sortedDestinationProvinceIds[SelectedDestinationProvinceIndex];
|
||||
private ProvinceView DestinationProvince => _model.Provinces[DestinationProvinceId];
|
||||
|
||||
private bool WouldAbandonProvince => unitSelector.SelectedActingUnits.Count() == OriginProvince.FullInfo.RulingFactionHeroIds.Count();
|
||||
private bool WouldAbandonProvince => unitSelector.SelectedActingUnits.Count() ==
|
||||
OriginProvince.FullInfo.RulingFactionHeroIds.Count();
|
||||
|
||||
private bool NotEnoughFood => SelectedFood < Math.Min(2 * FoodCost, SelectedOneProvinceCommand.FoodAvailable);
|
||||
private bool NotEnoughFood =>
|
||||
SelectedFood < Math.Min(2 * FoodCost, SelectedOneProvinceCommand.FoodAvailable);
|
||||
|
||||
private PlayerId? DestinationRuler = null;
|
||||
private bool MarchingOnTreatyPartner => (
|
||||
DestinationRuler.HasValue &&
|
||||
DestinationRuler.Value != playerId &&
|
||||
_model.MaybeDestroyedFaction(playerId).Treaties.ToList().Exists(t => t.TargetFactionId == DestinationRuler)
|
||||
);
|
||||
private bool MarchingOnTreatyPartner =>
|
||||
(DestinationRuler.HasValue && DestinationRuler.Value != playerId &&
|
||||
_model.MaybeDestroyedFaction(playerId).Treaties.ToList().Exists(
|
||||
t => t.TargetFactionId == DestinationRuler));
|
||||
|
||||
private bool BadlyConstructedUnits => unitSelector.HeroIdsLeadingInappropriateUnits.Count > 0;
|
||||
private bool BadlyConstructedUnits =>
|
||||
unitSelector.HeroIdsLeadingInappropriateUnits.Count > 0;
|
||||
|
||||
private bool NoBattalionsIntoEnemy => unitSelector.BattalionCount == 0 && DestinationProvince.RulingFactionId.HasValue && DestinationProvince.RulingFactionId.Value != playerId;
|
||||
private bool NoBattalionsIntoEnemy => unitSelector.BattalionCount == 0 &&
|
||||
DestinationProvince.RulingFactionId.HasValue &&
|
||||
DestinationProvince.RulingFactionId.Value != playerId;
|
||||
|
||||
public override bool WarnOnCommitButton => WouldAbandonProvince || NotEnoughFood || MarchingOnTreatyPartner || BadlyConstructedUnits || NoBattalionsIntoEnemy;
|
||||
public override string CommitWarningText
|
||||
{
|
||||
get
|
||||
{
|
||||
public override bool WarnOnCommitButton => WouldAbandonProvince || NotEnoughFood ||
|
||||
MarchingOnTreatyPartner ||
|
||||
BadlyConstructedUnits || NoBattalionsIntoEnemy;
|
||||
public override string CommitWarningText {
|
||||
get {
|
||||
if (!(WarnOnCommitButton)) return null;
|
||||
|
||||
string txt = "";
|
||||
if (WouldAbandonProvince)
|
||||
{
|
||||
if (WouldAbandonProvince) {
|
||||
txt = txt + "This action would abandon this province\n\n";
|
||||
}
|
||||
if (NotEnoughFood)
|
||||
{
|
||||
txt = txt + $"You have not selected enough food for your battalions for 2 months ({2 * FoodCost} needed)\n\n";
|
||||
if (NotEnoughFood) {
|
||||
txt = txt +
|
||||
$"You have not selected enough food for your battalions for 2 months ({2 * FoodCost} needed)\n\n";
|
||||
}
|
||||
if (MarchingOnTreatyPartner)
|
||||
{
|
||||
txt = txt + $"You have a treaty with {_model.FactionName(DestinationRuler.Value)}.\n\n";
|
||||
if (MarchingOnTreatyPartner) {
|
||||
txt = txt +
|
||||
$"You have a treaty with {_model.FactionName(DestinationRuler.Value)}.\n\n";
|
||||
} else if (NoBattalionsIntoEnemy) {
|
||||
txt = txt +
|
||||
$"{DestinationProvince.Name} is occupied by a hostile faction, and you have not selected any troops\n\n";
|
||||
}
|
||||
else if (NoBattalionsIntoEnemy)
|
||||
{
|
||||
txt = txt + $"{DestinationProvince.Name} is occupied by a hostile faction, and you have not selected any troops\n\n";
|
||||
}
|
||||
if (BadlyConstructedUnits)
|
||||
{
|
||||
if (BadlyConstructedUnits) {
|
||||
var count = unitSelector.HeroIdsLeadingInappropriateUnits.Count;
|
||||
if (count == 1)
|
||||
{
|
||||
txt = txt + $"{_model.Heroes[unitSelector.HeroIdsLeadingInappropriateUnits[0]].Name} is leading a battalion type that would restrict their abilities\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = txt + $"Some of your heroes are leading battalion types that would restrict their abilities\n\n";
|
||||
if (count == 1) {
|
||||
txt = txt +
|
||||
$"{_model.Heroes[unitSelector.HeroIdsLeadingInappropriateUnits[0]].Name} is leading a battalion type that would restrict their abilities\n\n";
|
||||
} else {
|
||||
txt = txt +
|
||||
$"Some of your heroes are leading battalion types that would restrict their abilities\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,19 +136,16 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
private MarchCommandFromOneProvince SelectedOneProvinceCommand => sortedOneProvinceCommands[SelectedOriginProvinceIndex];
|
||||
private MarchCommandFromOneProvince SelectedOneProvinceCommand =>
|
||||
sortedOneProvinceCommands[SelectedOriginProvinceIndex];
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => sortedDestinationProvinceIds[SelectedDestinationProvinceIndex];
|
||||
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index = sortedDestinationProvinceIds.IndexOf(value.Value);
|
||||
if (index != -1)
|
||||
toDropdown.value = index;
|
||||
if (index != -1) toDropdown.value = index;
|
||||
else
|
||||
toDropdown.value = 0;
|
||||
}
|
||||
@@ -148,35 +153,27 @@ namespace eagle
|
||||
}
|
||||
|
||||
public int FoodCost => (int)Math.Ceiling(
|
||||
SelectedActingUnits
|
||||
.Where(u => u.BattalionId.HasValue)
|
||||
SelectedActingUnits.Where(u => u.BattalionId.HasValue)
|
||||
.Select(u => u.BattalionId.Value)
|
||||
.Select(bid => SelectedOneProvinceCommand.AvailableBattalions.First(bwfc => bwfc.BattalionId == bid))
|
||||
.Select(bid => SelectedOneProvinceCommand.AvailableBattalions.First(
|
||||
bwfc => bwfc.BattalionId == bid))
|
||||
.Select(bwfc => bwfc.MonthlyFood)
|
||||
.Sum()
|
||||
);
|
||||
.Sum());
|
||||
|
||||
public override bool EnableCommitButton => (
|
||||
unitSelector.UnitsAreValid
|
||||
&& (SelectedFood >= FoodCost || SelectedFood >= SelectedOneProvinceCommand.FoodAvailable)
|
||||
&& SelectedFood <= SelectedOneProvinceCommand.FoodAvailable
|
||||
&& SelectedGold >= SelectedOneProvinceCommand.GoldCost
|
||||
&& SelectedGold <= SelectedOneProvinceCommand.GoldAvailable
|
||||
);
|
||||
public override string DisabledCommitButtonReason
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SelectedGold > SelectedOneProvinceCommand.GoldAvailable)
|
||||
{
|
||||
public override bool EnableCommitButton =>
|
||||
(unitSelector.UnitsAreValid &&
|
||||
(SelectedFood >= FoodCost ||
|
||||
SelectedFood >= SelectedOneProvinceCommand.FoodAvailable) &&
|
||||
SelectedFood <= SelectedOneProvinceCommand.FoodAvailable &&
|
||||
SelectedGold >= SelectedOneProvinceCommand.GoldCost &&
|
||||
SelectedGold <= SelectedOneProvinceCommand.GoldAvailable);
|
||||
public override string DisabledCommitButtonReason {
|
||||
get {
|
||||
if (SelectedGold > SelectedOneProvinceCommand.GoldAvailable) {
|
||||
return "Trying to send more gold than available";
|
||||
}
|
||||
else if (SelectedFood > SelectedOneProvinceCommand.FoodAvailable)
|
||||
{
|
||||
} else if (SelectedFood > SelectedOneProvinceCommand.FoodAvailable) {
|
||||
return "Trying to send more food than available";
|
||||
}
|
||||
else if (SelectedFood < FoodCost)
|
||||
{
|
||||
} else if (SelectedFood < FoodCost) {
|
||||
return $"Must send at least {FoodCost} food";
|
||||
}
|
||||
|
||||
@@ -184,14 +181,14 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUpDestinationProvinceDropdown()
|
||||
{
|
||||
sortedDestinationProvinceIds = SelectedOneProvinceCommand
|
||||
.AvailableDestinationProvinces
|
||||
private void SetUpDestinationProvinceDropdown() {
|
||||
sortedDestinationProvinceIds = SelectedOneProvinceCommand.AvailableDestinationProvinces
|
||||
.OrderBy(pid => _model.Provinces[pid].Name)
|
||||
.ToList();
|
||||
var destinationProvinceNames = sortedDestinationProvinceIds
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList();
|
||||
|
||||
toDropdown.ClearOptions();
|
||||
@@ -201,40 +198,41 @@ namespace eagle
|
||||
toDropdown.value = 0;
|
||||
}
|
||||
|
||||
private void SetUpUnitSelector()
|
||||
{
|
||||
private void SetUpUnitSelector() {
|
||||
var dict = new Dictionary<HeroId, List<BattalionIdWithSuitability>>();
|
||||
foreach (var kv in SelectedOneProvinceCommand.SuitableBattalionsForHeroes)
|
||||
{
|
||||
foreach (var kv in SelectedOneProvinceCommand.SuitableBattalionsForHeroes) {
|
||||
dict.Add(kv.Key, kv.Value.BattalionIdsWithSuitability.ToList());
|
||||
}
|
||||
|
||||
var recommendedConfig = SelectedOneProvinceCommand.RecommendedBattleConfig;
|
||||
List<CombatUnit> recommendedUnits = recommendedConfig == null ? new List<CombatUnit>() : recommendedConfig.Units.ToList();
|
||||
List<CombatUnit> recommendedUnits = recommendedConfig == null
|
||||
? new List<CombatUnit>()
|
||||
: recommendedConfig.Units.ToList();
|
||||
recommendedFood = recommendedConfig == null ? 0 : recommendedConfig.Food;
|
||||
recommendedGold = recommendedConfig == null ? 0 : recommendedConfig.Gold;
|
||||
|
||||
var province = _model.Provinces[SelectedOneProvinceCommand.OriginProvinceId];
|
||||
var availableBattalionIds = SelectedOneProvinceCommand.AvailableBattalions.Select(b => b.BattalionId).ToList();
|
||||
var orderedBattalions = ProvinceUtils.OrderedBattalions(province).Where(batt => availableBattalionIds.Contains(batt.Id)).ToList();
|
||||
var availableBattalionIds =
|
||||
SelectedOneProvinceCommand.AvailableBattalions.Select(b => b.BattalionId)
|
||||
.ToList();
|
||||
var orderedBattalions = ProvinceUtils.OrderedBattalions(province)
|
||||
.Where(batt => availableBattalionIds.Contains(batt.Id))
|
||||
.ToList();
|
||||
|
||||
unitSelector.SetUpUnits(
|
||||
_model,
|
||||
SelectedOneProvinceCommand.AvailableHeroIds.ToList(),
|
||||
orderedBattalions,
|
||||
dict,
|
||||
recommendedUnits
|
||||
);
|
||||
recommendedUnits);
|
||||
}
|
||||
|
||||
public void RecommendedButtonClicked()
|
||||
{
|
||||
public void RecommendedButtonClicked() {
|
||||
foodSlider.value = recommendedFood;
|
||||
goldSlider.value = recommendedGold;
|
||||
}
|
||||
|
||||
public void FromDropdownValueChanged(Int32 newValue)
|
||||
{
|
||||
public void FromDropdownValueChanged(Int32 newValue) {
|
||||
SetUpDestinationProvinceDropdown();
|
||||
SetUpUnitSelector();
|
||||
|
||||
@@ -251,18 +249,16 @@ namespace eagle
|
||||
goldSlider.value = SelectedOneProvinceCommand.GoldCost;
|
||||
}
|
||||
|
||||
public void ToDropdownValueChanged(Int32 newValue)
|
||||
{
|
||||
}
|
||||
public void ToDropdownValueChanged(Int32 newValue) {}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
sortedOneProvinceCommands = MarchAvailableCommand
|
||||
.OneProvinceCommands
|
||||
protected override void SetUpUI() {
|
||||
sortedOneProvinceCommands =
|
||||
MarchAvailableCommand.OneProvinceCommands
|
||||
.OrderBy(cmd => _model.Provinces[cmd.OriginProvinceId].Name)
|
||||
.ToList();
|
||||
|
||||
var availableOriginProvinceNames = sortedOneProvinceCommands
|
||||
var availableOriginProvinceNames =
|
||||
sortedOneProvinceCommands
|
||||
.Select(cmd => _model.Provinces[cmd.OriginProvinceId].Name)
|
||||
.ToList();
|
||||
|
||||
@@ -271,13 +267,11 @@ namespace eagle
|
||||
fromDropdown.onValueChanged.RemoveAllListeners();
|
||||
fromDropdown.onValueChanged.AddListener(FromDropdownValueChanged);
|
||||
|
||||
var thisProvinceIndex = sortedOneProvinceCommands.FindIndex(cmd => cmd.OriginProvinceId == ActingProvinceId);
|
||||
if (thisProvinceIndex == -1)
|
||||
{
|
||||
var thisProvinceIndex = sortedOneProvinceCommands.FindIndex(
|
||||
cmd => cmd.OriginProvinceId == ActingProvinceId);
|
||||
if (thisProvinceIndex == -1) {
|
||||
fromDropdown.value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fromDropdown.value = thisProvinceIndex;
|
||||
}
|
||||
|
||||
@@ -295,46 +289,37 @@ namespace eagle
|
||||
goldSlider.maxValue = SelectedOneProvinceCommand.GoldAvailable;
|
||||
|
||||
foodSlider.value = 0;
|
||||
goldSlider.value = Math.Min(SelectedOneProvinceCommand.GoldCost, SelectedOneProvinceCommand.GoldAvailable);
|
||||
goldSlider.value = Math.Min(
|
||||
SelectedOneProvinceCommand.GoldCost,
|
||||
SelectedOneProvinceCommand.GoldAvailable);
|
||||
|
||||
setFoodLabels();
|
||||
setGoldLabels();
|
||||
}
|
||||
|
||||
public void onGoldSliderChanged(float value)
|
||||
{
|
||||
setGoldLabels();
|
||||
}
|
||||
public void onGoldSliderChanged(float value) { setGoldLabels(); }
|
||||
|
||||
public void onFoodSliderChanged(float value)
|
||||
{
|
||||
setFoodLabels();
|
||||
}
|
||||
public void onFoodSliderChanged(float value) { setFoodLabels(); }
|
||||
|
||||
public void setGoldLabels()
|
||||
{
|
||||
public void setGoldLabels() {
|
||||
int taken = (int)goldSlider.value;
|
||||
int left = (int)goldSlider.maxValue - taken;
|
||||
goldTakenLabel.text = taken.ToString();
|
||||
goldLeftLabel.text = left.ToString();
|
||||
}
|
||||
|
||||
public void setFoodLabels()
|
||||
{
|
||||
public void setFoodLabels() {
|
||||
int taken = (int)foodSlider.value;
|
||||
int left = (int)foodSlider.maxValue - taken;
|
||||
foodTakenLabel.text = taken.ToString();
|
||||
foodLeftLabel.text = left.ToString();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
MarchCommand = new MarchSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var cmd = new SelectedCommand {
|
||||
MarchCommand =
|
||||
new MarchSelectedCommand {
|
||||
DestinationProvinceId = DestinationProvinceId,
|
||||
Food = SelectedSupplies.food,
|
||||
Gold = SelectedSupplies.gold,
|
||||
|
||||
+277
-340
File diff suppressed because it is too large
Load Diff
+26
-37
@@ -5,14 +5,11 @@ using Net.Eagle0.Eagle.Api;
|
||||
using System;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class PleaseRecruitMeCommandSelector : PopupPanelController
|
||||
{
|
||||
struct HeroInfo
|
||||
{
|
||||
public class PleaseRecruitMeCommandSelector : PopupPanelController {
|
||||
struct HeroInfo {
|
||||
public ProvinceId provinceId;
|
||||
public ExpandedUnaffiliatedHero hero;
|
||||
}
|
||||
@@ -25,31 +22,29 @@ namespace eagle
|
||||
|
||||
public int CommandIndex { get; set; }
|
||||
private AvailableCommand _availableCommand = null;
|
||||
public AvailableCommand AvailableCommand
|
||||
{
|
||||
public AvailableCommand AvailableCommand {
|
||||
get => _availableCommand;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableCommand = value;
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
_offers = new List<HeroInfo>();
|
||||
PopupInfos = new List<PopupInfo>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_offers = _availableCommand
|
||||
.PleaseRecruitMeCommand
|
||||
.AvailableProvinces
|
||||
.SelectMany(p => p.AvailableHeroes.Select(h => new HeroInfo { provinceId = p.ProvinceId, hero = h })).ToList();
|
||||
} else {
|
||||
_offers = _availableCommand.PleaseRecruitMeCommand.AvailableProvinces
|
||||
.SelectMany(
|
||||
p => p.AvailableHeroes.Select(
|
||||
h => new HeroInfo {
|
||||
provinceId = p.ProvinceId,
|
||||
hero = h
|
||||
}))
|
||||
.ToList();
|
||||
|
||||
PopupInfos = _offers
|
||||
.Select(heroInfo => new PopupInfo
|
||||
{
|
||||
PopupInfos = _offers.Select(heroInfo => new PopupInfo {
|
||||
titleText = "Please Recruit Me!",
|
||||
mainText = "",
|
||||
affectedProvinceIds = new List<ProvinceId>()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList();
|
||||
|
||||
SetUpPanel();
|
||||
}
|
||||
@@ -58,12 +53,10 @@ namespace eagle
|
||||
|
||||
private List<HeroInfo> _offers = new List<HeroInfo>();
|
||||
|
||||
public SelectedCommand selectedCommand(bool accept)
|
||||
{
|
||||
return new SelectedCommand
|
||||
{
|
||||
PleaseRecruitMeCommand = new PleaseRecruitMeSelectedCommand
|
||||
{
|
||||
public SelectedCommand selectedCommand(bool accept) {
|
||||
return new SelectedCommand {
|
||||
PleaseRecruitMeCommand =
|
||||
new PleaseRecruitMeSelectedCommand {
|
||||
ProvinceId = _offers[DisplayedIndex].provinceId,
|
||||
HeroId = _offers[DisplayedIndex].hero.Hero.Id,
|
||||
Accept = accept
|
||||
@@ -71,26 +64,22 @@ namespace eagle
|
||||
};
|
||||
}
|
||||
|
||||
public void AcceptButtonClicked()
|
||||
{
|
||||
public void AcceptButtonClicked() {
|
||||
submissionAction(selectedCommand(true));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void RejectButtonClicked()
|
||||
{
|
||||
public void RejectButtonClicked() {
|
||||
submissionAction(selectedCommand(false));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
override protected void SetUpPanel()
|
||||
{
|
||||
override protected void SetUpPanel() {
|
||||
base.SetUpPanel();
|
||||
|
||||
if (_offers.Count > DisplayedIndex)
|
||||
{
|
||||
if (_offers.Count > DisplayedIndex) {
|
||||
heroDetailsController.SetHero(_offers[DisplayedIndex].hero.Hero, Model);
|
||||
}
|
||||
}
|
||||
|
||||
+78
-100
@@ -8,26 +8,30 @@ using UnityEngine;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using FactionId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class RansomCommandSelector : CommandSelector
|
||||
{
|
||||
private FactionId SelectedFactionId => AvailableTargetFactionIds[targetFactionDropdown.value];
|
||||
private PrisonerToBeRansomed SelectedPrisonerToBeRansomed => AvailablePrisonersToBeRansomed[prisonerToBeRansomedDropdown.value];
|
||||
public class RansomCommandSelector : CommandSelector {
|
||||
private FactionId SelectedFactionId =>
|
||||
AvailableTargetFactionIds[targetFactionDropdown.value];
|
||||
private PrisonerToBeRansomed SelectedPrisonerToBeRansomed =>
|
||||
AvailablePrisonersToBeRansomed[prisonerToBeRansomedDropdown.value];
|
||||
|
||||
private RansomOffer RansomOffer => DiplomacyCommand
|
||||
.Options
|
||||
.Where(opt => opt.SealedValueCase == DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
private RansomOffer RansomOffer =>
|
||||
DiplomacyCommand.Options
|
||||
.Where(opt => opt.SealedValueCase ==
|
||||
DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
.Select(opt => opt.RansomOfferOption)
|
||||
.First(opt => opt.TargetFactionId == SelectedFactionId)
|
||||
.RansomOffer;
|
||||
|
||||
public override bool IsAppropriateFor(AvailableCommand cmd) =>
|
||||
cmd.SealedValueCase == CommandType && cmd.DiplomacyCommand.Options.Any(opt => opt.SealedValueCase == DiplomacyOption.SealedValueOneofCase.RansomOfferOption);
|
||||
cmd.SealedValueCase == CommandType
|
||||
&& cmd.DiplomacyCommand.Options.Any(
|
||||
opt => opt.SealedValueCase ==
|
||||
DiplomacyOption.SealedValueOneofCase.RansomOfferOption);
|
||||
|
||||
private DiplomacyAvailableCommand DiplomacyCommand => _availableCommand.DiplomacyCommand;
|
||||
private ProvinceId ActingProvinceId => DiplomacyCommand.ActingProvinceId;
|
||||
@@ -40,75 +44,65 @@ namespace eagle
|
||||
public EventBasedTable hostagesTable;
|
||||
public EventBasedTable prisonersTable;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.DiplomacyCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.DiplomacyCommand;
|
||||
public override string HeaderString => "Offer Ransom";
|
||||
public override string CommitButtonString => "Commit Ransom Offer";
|
||||
|
||||
private List<HeroId> HostageHeroIds { get; set; }
|
||||
private List<HeroId> PrisonerHeroIds { get; set; }
|
||||
|
||||
public override List<HeroId> TargetedHeroIds
|
||||
{
|
||||
get
|
||||
{
|
||||
public override List<HeroId> TargetedHeroIds {
|
||||
get {
|
||||
var hids = new List<HeroId>(HostageHeroIds);
|
||||
hids.AddRange(PrisonerHeroIds);
|
||||
return hids;
|
||||
}
|
||||
}
|
||||
public override bool HeroIsTargetable(HeroId heroId) => AvailableHostages.Contains(heroId) || AvailablePrisoners.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId)
|
||||
{
|
||||
if (AvailableHostages.Contains(heroId))
|
||||
{
|
||||
if (!HostageHeroIds.Contains(heroId))
|
||||
{
|
||||
HostageHeroIds.Add(heroId);
|
||||
}
|
||||
}
|
||||
else if (AvailablePrisoners.Contains(heroId))
|
||||
{
|
||||
if (!PrisonerHeroIds.Contains(heroId))
|
||||
{
|
||||
PrisonerHeroIds.Add(heroId);
|
||||
}
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
AvailableHostages.Contains(heroId) || AvailablePrisoners.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) {
|
||||
if (AvailableHostages.Contains(heroId)) {
|
||||
if (!HostageHeroIds.Contains(heroId)) { HostageHeroIds.Add(heroId); }
|
||||
} else if (AvailablePrisoners.Contains(heroId)) {
|
||||
if (!PrisonerHeroIds.Contains(heroId)) { PrisonerHeroIds.Add(heroId); }
|
||||
}
|
||||
|
||||
UpdateTables();
|
||||
}
|
||||
public override void RemoveTargetedHero(HeroId heroId)
|
||||
{
|
||||
public override void RemoveTargetedHero(HeroId heroId) {
|
||||
HostageHeroIds.Remove(heroId);
|
||||
PrisonerHeroIds.Remove(heroId);
|
||||
}
|
||||
|
||||
public override List<FactionId> TargetedFactionIds => new List<FactionId> { SelectedFactionId };
|
||||
public override bool FactionIsTargetable(FactionId factionId) => AvailableTargetFactionIds.Contains(factionId);
|
||||
public override void AddTargetedFaction(FactionId factionId) => targetFactionDropdown.value = AvailableTargetFactionIds.IndexOf(factionId);
|
||||
public override List<FactionId> TargetedFactionIds =>
|
||||
new List<FactionId> { SelectedFactionId };
|
||||
public override bool FactionIsTargetable(FactionId factionId) =>
|
||||
AvailableTargetFactionIds.Contains(factionId);
|
||||
public override void AddTargetedFaction(FactionId factionId) =>
|
||||
targetFactionDropdown.value = AvailableTargetFactionIds.IndexOf(factionId);
|
||||
|
||||
public override bool WarnOnCommitButton => PrisonerHeroIds.Exists(hid => _model.ActiveFactions[_model.PlayerId.Value].Leaders.Contains(hid));
|
||||
public override string CommitWarningText => "You're offering up a faction leader. Are you sure?";
|
||||
public override bool WarnOnCommitButton => PrisonerHeroIds.Exists(
|
||||
hid => _model.ActiveFactions[_model.PlayerId.Value].Leaders.Contains(hid));
|
||||
public override string CommitWarningText =>
|
||||
"You're offering up a faction leader. Are you sure?";
|
||||
|
||||
public override bool EnableCommitButton => GoldOffered > 0 || PrisonerHeroIds.Any() || HostageHeroIds.Any();
|
||||
public override bool EnableCommitButton => GoldOffered > 0 ||
|
||||
PrisonerHeroIds.Any() || HostageHeroIds.Any();
|
||||
|
||||
private List<FactionId> AvailableTargetFactionIds { get; set; }
|
||||
private List<PrisonerToBeRansomed> AvailablePrisonersToBeRansomed { get; set; }
|
||||
private List<HeroId> AvailableHostages { get; set; }
|
||||
private List<HeroId> AvailablePrisoners { get; set; }
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => null;
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
var targetFaction = _model.Provinces[value.Value].RulingFactionId;
|
||||
if (targetFaction.HasValue)
|
||||
{
|
||||
if (targetFaction.HasValue) {
|
||||
var dropdownIndex = AvailableTargetFactionIds.IndexOf(targetFaction.Value);
|
||||
if (dropdownIndex != -1)
|
||||
{
|
||||
if (dropdownIndex != -1) {
|
||||
targetFactionDropdown.value = dropdownIndex;
|
||||
SetOptions();
|
||||
}
|
||||
@@ -117,22 +111,18 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
private FactionId TargetFactionId(DiplomacyOption option)
|
||||
{
|
||||
private FactionId TargetFactionId(DiplomacyOption option) {
|
||||
return option.RansomOfferOption.TargetFactionId;
|
||||
}
|
||||
|
||||
private int GoldOffered => (int)goldSlider.value;
|
||||
|
||||
private RansomOfferOption SelectedOption
|
||||
{
|
||||
get
|
||||
{
|
||||
var opt = new RansomOfferOption
|
||||
{
|
||||
private RansomOfferOption SelectedOption {
|
||||
get {
|
||||
var opt = new RansomOfferOption {
|
||||
TargetFactionId = SelectedFactionId,
|
||||
RansomOffer = new RansomOffer
|
||||
{
|
||||
RansomOffer =
|
||||
new RansomOffer {
|
||||
OfferingFactionId = _model.PlayerId.Value,
|
||||
TargetFactionId = SelectedFactionId,
|
||||
MessengerOriginProvinceId = ActingProvinceId,
|
||||
@@ -141,27 +131,27 @@ namespace eagle
|
||||
}
|
||||
};
|
||||
|
||||
opt.RansomOffer.HostagesOffered.AddRange(RansomOffer.HostagesOffered.Where(ho => HostageHeroIds.Contains(ho.HeroId)));
|
||||
opt.RansomOffer.PrisonersOffered.AddRange(RansomOffer.PrisonersOffered.Where(ho => PrisonerHeroIds.Contains(ho.HeroId)));
|
||||
opt.RansomOffer.HostagesOffered.AddRange(RansomOffer.HostagesOffered.Where(
|
||||
ho => HostageHeroIds.Contains(ho.HeroId)));
|
||||
opt.RansomOffer.PrisonersOffered.AddRange(RansomOffer.PrisonersOffered.Where(
|
||||
ho => PrisonerHeroIds.Contains(ho.HeroId)));
|
||||
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
AvailableTargetFactionIds = DiplomacyCommand
|
||||
.Options
|
||||
.Where(opt => opt.SealedValueCase == DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
protected override void SetUpUI() {
|
||||
AvailableTargetFactionIds =
|
||||
DiplomacyCommand.Options
|
||||
.Where(opt => opt.SealedValueCase ==
|
||||
DiplomacyOption.SealedValueOneofCase.RansomOfferOption)
|
||||
.Select(opt => TargetFactionId(opt))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
targetFactionDropdown.ClearOptions();
|
||||
targetFactionDropdown.AddOptions(
|
||||
AvailableTargetFactionIds
|
||||
.Select(fid => _model.FactionName(fid))
|
||||
.ToList());
|
||||
AvailableTargetFactionIds.Select(fid => _model.FactionName(fid)).ToList());
|
||||
targetFactionDropdown.value = 0;
|
||||
|
||||
goldSlider.minValue = 0;
|
||||
@@ -175,41 +165,34 @@ namespace eagle
|
||||
SetOptions();
|
||||
}
|
||||
|
||||
public void ToggleChanged()
|
||||
{
|
||||
}
|
||||
public void ToggleChanged() {}
|
||||
|
||||
public void SliderChanged()
|
||||
{
|
||||
goldAmount.text = ((int)goldSlider.value).ToString();
|
||||
}
|
||||
public void SliderChanged() { goldAmount.text = ((int)goldSlider.value).ToString(); }
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
DiplomacyCommand = new DiplomacySelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
DiplomacyCommand =
|
||||
new DiplomacySelectedCommand {
|
||||
TargetFactionId = SelectedFactionId,
|
||||
SelectedOption = new DiplomacyOption { RansomOfferOption = SelectedOption }
|
||||
}
|
||||
};
|
||||
|
||||
public void TargetDropdownChanged(int value)
|
||||
{
|
||||
SetOptions();
|
||||
}
|
||||
public void TargetDropdownChanged(int value) { SetOptions(); }
|
||||
|
||||
private void SetOptions()
|
||||
{
|
||||
private void SetOptions() {
|
||||
var targetFid = SelectedFactionId;
|
||||
var options = _availableCommand.DiplomacyCommand.Options.Select(opt => opt.RansomOfferOption).Where(opt => opt != null && opt.TargetFactionId == targetFid);
|
||||
var options =
|
||||
_availableCommand.DiplomacyCommand.Options.Select(opt => opt.RansomOfferOption)
|
||||
.Where(opt => opt != null && opt.TargetFactionId == targetFid);
|
||||
goldSlider.maxValue = options.First().RansomOffer.GoldOffered;
|
||||
|
||||
AvailablePrisonersToBeRansomed = options
|
||||
.Select(opt => opt.RansomOffer.PrisonerToBeRansomed).ToList();
|
||||
AvailablePrisonersToBeRansomed =
|
||||
options.Select(opt => opt.RansomOffer.PrisonerToBeRansomed).ToList();
|
||||
|
||||
prisonerToBeRansomedDropdown.ClearOptions();
|
||||
prisonerToBeRansomedDropdown.AddOptions(
|
||||
AvailablePrisonersToBeRansomed.Select(p => _model.Heroes[p.PrisonerHeroId].Name).ToList());
|
||||
AvailablePrisonersToBeRansomed.Select(p => _model.Heroes[p.PrisonerHeroId].Name)
|
||||
.ToList());
|
||||
prisonerToBeRansomedDropdown.value = 0;
|
||||
|
||||
AvailableHostages = RansomOffer.HostagesOffered.Select(p => p.HeroId).ToList();
|
||||
@@ -218,11 +201,9 @@ namespace eagle
|
||||
UpdateTables();
|
||||
}
|
||||
|
||||
private void UpdateTables()
|
||||
{
|
||||
private void UpdateTables() {
|
||||
prisonersTable.RowCount = 0;
|
||||
foreach (HeroId prisonerHid in PrisonerHeroIds)
|
||||
{
|
||||
foreach (HeroId prisonerHid in PrisonerHeroIds) {
|
||||
var row = prisonersTable.AddRowWithComponent<AvailableHeroTableRow>();
|
||||
row.HeroName = _model.Heroes[prisonerHid].Name;
|
||||
row.Selectable = true;
|
||||
@@ -230,8 +211,7 @@ namespace eagle
|
||||
}
|
||||
|
||||
hostagesTable.RowCount = 0;
|
||||
foreach (HeroId hostageHid in HostageHeroIds)
|
||||
{
|
||||
foreach (HeroId hostageHid in HostageHeroIds) {
|
||||
var row = hostagesTable.AddRowWithComponent<AvailableHeroTableRow>();
|
||||
row.HeroName = _model.Heroes[hostageHid].Name;
|
||||
row.Selectable = true;
|
||||
@@ -239,14 +219,12 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public void HostageTableRowClicked(int index)
|
||||
{
|
||||
public void HostageTableRowClicked(int index) {
|
||||
HostageHeroIds.RemoveAt(index);
|
||||
UpdateTables();
|
||||
}
|
||||
|
||||
public void PrisonerTableRowClicked(int index)
|
||||
{
|
||||
public void PrisonerTableRowClicked(int index) {
|
||||
PrisonerHeroIds.RemoveAt(index);
|
||||
UpdateTables();
|
||||
}
|
||||
|
||||
+22
-30
@@ -6,63 +6,58 @@ using Net.Eagle0.Eagle.Common;
|
||||
using EagleGUIUtils;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class ReconCommandSelector : CommandSelector
|
||||
{
|
||||
public class ReconCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public TMP_Dropdown destinationDropdown;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ReconCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ReconCommand;
|
||||
public override string HeaderString => "Recon";
|
||||
public override string CommitButtonString => "Commit Recon";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => ReconAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
ReconAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private ReconAvailableCommand ReconAvailableCommand => _availableCommand.ReconCommand;
|
||||
private ProvinceId ActingProvinceId => ReconAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => ReconAvailableCommand.AvailableTargetProvinces[destinationDropdown.value];
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index = ReconAvailableCommand.AvailableTargetProvinces.IndexOf(value.Value);
|
||||
if (index != -1)
|
||||
destinationDropdown.value = index;
|
||||
if (index != -1) destinationDropdown.value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand
|
||||
{
|
||||
ReconSelectedCommand = new ReconSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ReconSelectedCommand =
|
||||
new ReconSelectedCommand {
|
||||
ActingHeroId = SelectedHeroId,
|
||||
TargetProvinceId = TargetedProvince.Value
|
||||
}
|
||||
};
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = ReconAvailableCommand
|
||||
.AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
ReconAvailableCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
|
||||
destinationDropdown.ClearOptions();
|
||||
var destinationProvinceNames = ReconAvailableCommand.AvailableTargetProvinces
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList();
|
||||
|
||||
destinationDropdown.AddOptions(destinationProvinceNames);
|
||||
@@ -70,9 +65,6 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+18
-30
@@ -5,71 +5,59 @@ using TMPro;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class RecruitHeroesCommandSelector : CommandSelector
|
||||
{
|
||||
public class RecruitHeroesCommandSelector : CommandSelector {
|
||||
public HeroDetailsController heroDetails;
|
||||
public Button nextHeroButton;
|
||||
public TMP_Text statusText;
|
||||
|
||||
private int selectedHeroIndex;
|
||||
|
||||
private RecruitHeroesAvailableCommand RecruitHeroesCommand => _availableCommand.RecruitHeroesCommand;
|
||||
private RecruitHeroesAvailableCommand RecruitHeroesCommand =>
|
||||
_availableCommand.RecruitHeroesCommand;
|
||||
private ProvinceId ActingProvinceId => RecruitHeroesCommand.ActingProvinceId;
|
||||
private ExpandedUnaffiliatedHero SelectedHero => RecruitHeroesCommand.AvailableHeroes.ToList()[selectedHeroIndex];
|
||||
private ExpandedUnaffiliatedHero SelectedHero =>
|
||||
RecruitHeroesCommand.AvailableHeroes.ToList()[selectedHeroIndex];
|
||||
private int HeroCount => RecruitHeroesCommand.AvailableHeroes.Count;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.RecruitHeroesCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.RecruitHeroesCommand;
|
||||
public override string HeaderString => "Recruit Heroes";
|
||||
public override string CommitButtonString => "Commit Recruit";
|
||||
|
||||
public override bool HeroIsTargetable(HeroId heroId) => RecruitHeroesCommand.AvailableHeroes.Any(euh => euh.Hero.Id == heroId);
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
RecruitHeroesCommand.AvailableHeroes.Any(euh => euh.Hero.Id == heroId);
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHero.Hero.Id };
|
||||
|
||||
void DisplayHero()
|
||||
{
|
||||
void DisplayHero() {
|
||||
heroDetails.SetHero(SelectedHero.Hero, _model);
|
||||
statusText.text = DisplayNames.UnaffiliatedHeroStatus(SelectedHero.Type);
|
||||
nextHeroButton.gameObject.SetActive(HeroCount > 1);
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
if (selectedHeroIndex >= HeroCount)
|
||||
{
|
||||
selectedHeroIndex = 0;
|
||||
}
|
||||
protected override void SetUpUI() {
|
||||
if (selectedHeroIndex >= HeroCount) { selectedHeroIndex = 0; }
|
||||
DisplayHero();
|
||||
nextHeroButton.gameObject.SetActive(HeroCount > 1);
|
||||
}
|
||||
|
||||
public override SelectedCommand Command
|
||||
{
|
||||
get
|
||||
{
|
||||
public override SelectedCommand Command {
|
||||
get {
|
||||
var rhc = new RecruitHeroesSelectedCommand();
|
||||
rhc.HeroIds.Add(SelectedHero.Hero.Id);
|
||||
|
||||
var cmd = new SelectedCommand
|
||||
{
|
||||
RecruitHeroesCommand = rhc
|
||||
};
|
||||
var cmd = new SelectedCommand { RecruitHeroesCommand = rhc };
|
||||
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
public void NextHero()
|
||||
{
|
||||
public void NextHero() {
|
||||
selectedHeroIndex++;
|
||||
if (selectedHeroIndex >= HeroCount)
|
||||
{
|
||||
selectedHeroIndex = 0;
|
||||
}
|
||||
if (selectedHeroIndex >= HeroCount) { selectedHeroIndex = 0; }
|
||||
DisplayHero();
|
||||
}
|
||||
}
|
||||
|
||||
+29
-35
@@ -6,12 +6,10 @@ using System.Linq;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class ResolveInvitationCommandSelector : PopupPanelController
|
||||
{
|
||||
public class ResolveInvitationCommandSelector : PopupPanelController {
|
||||
public GameObject panel;
|
||||
|
||||
public Action<SelectedCommand> submissionAction;
|
||||
@@ -23,71 +21,67 @@ namespace eagle
|
||||
|
||||
public int CommandIndex { get; set; }
|
||||
private AvailableCommand _availableCommand = null;
|
||||
public AvailableCommand AvailableCommand
|
||||
{
|
||||
public AvailableCommand AvailableCommand {
|
||||
get => _availableCommand;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableCommand = value;
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
PopupInfos = new List<PopupInfo>();
|
||||
}
|
||||
else
|
||||
{
|
||||
PopupInfos = _availableCommand.ResolveInvitationCommand.Invitations.Select(invite => new PopupInfo
|
||||
{
|
||||
} else {
|
||||
PopupInfos =
|
||||
_availableCommand.ResolveInvitationCommand.Invitations
|
||||
.Select(invite => new PopupInfo {
|
||||
titleText = "Invited",
|
||||
mainText = $"{Model.Heroes[invite.MessengerHeroId].Name} brings an invitation to join {Model.FactionName(invite.OriginatingFactionId)}. This would end your game. Don't accept this bullshit.",
|
||||
mainText =
|
||||
$"{Model.Heroes[invite.MessengerHeroId].Name} brings an invitation to join {Model.FactionName(invite.OriginatingFactionId)}. This would end your game. Don't accept this bullshit.",
|
||||
affectedProvinceIds = new List<ProvinceId>()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList();
|
||||
|
||||
SetUpPanel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SelectedCommand selectedCommand(DiplomacyOfferStatus resolution) => new SelectedCommand
|
||||
{
|
||||
ResolveInvitationCommand = new ResolveInvitationSelectedCommand
|
||||
{
|
||||
public SelectedCommand selectedCommand(DiplomacyOfferStatus resolution) =>
|
||||
new SelectedCommand {
|
||||
ResolveInvitationCommand =
|
||||
new ResolveInvitationSelectedCommand {
|
||||
Resolution = resolution,
|
||||
OriginatingFactionId = _availableCommand.ResolveInvitationCommand.Invitations[DisplayedIndex].OriginatingFactionId
|
||||
OriginatingFactionId = _availableCommand.ResolveInvitationCommand
|
||||
.Invitations[DisplayedIndex]
|
||||
.OriginatingFactionId
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public void AcceptButtonClicked()
|
||||
{
|
||||
public void AcceptButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Accepted));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void RejectButtonClicked()
|
||||
{
|
||||
public void RejectButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Rejected));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void ImprisonButtonClicked()
|
||||
{
|
||||
public void ImprisonButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Imprisoned));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
override protected void SetUpPanel()
|
||||
{
|
||||
override protected void SetUpPanel() {
|
||||
base.SetUpPanel();
|
||||
|
||||
if (_availableCommand?.ResolveInvitationCommand?.Invitations.Count > DisplayedIndex)
|
||||
{
|
||||
var invitation = _availableCommand.ResolveInvitationCommand.Invitations[DisplayedIndex];
|
||||
if (_availableCommand?.ResolveInvitationCommand?.Invitations.Count > DisplayedIndex) {
|
||||
var invitation =
|
||||
_availableCommand.ResolveInvitationCommand.Invitations[DisplayedIndex];
|
||||
heroDetailsController.SetHero(Model.Heroes[invitation.MessengerHeroId], Model);
|
||||
var invitingFaction = Model.ActiveFactions[invitation.OriginatingFactionId];
|
||||
FactionHeadshot.texture = GetComponentInParent<AWSResourceFetcher>().GetImage(Model.Heroes[invitingFaction.FactionHeadId].ImagePath);
|
||||
FactionHeadshot.texture = GetComponentInParent<AWSResourceFetcher>().GetImage(
|
||||
Model.Heroes[invitingFaction.FactionHeadId].ImagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+44
-60
@@ -6,12 +6,10 @@ using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class ResolveRansomOfferCommandSelector : PopupPanelController
|
||||
{
|
||||
public class ResolveRansomOfferCommandSelector : PopupPanelController {
|
||||
public Action<SelectedCommand> submissionAction;
|
||||
|
||||
public GameModel Model { get; set; }
|
||||
@@ -24,8 +22,7 @@ namespace eagle
|
||||
|
||||
public EventBasedTable exchangedHeroesTable;
|
||||
|
||||
private string MainText(RansomOffer offer)
|
||||
{
|
||||
private string MainText(RansomOffer offer) {
|
||||
var originatingFactionId = offer.OfferingFactionId;
|
||||
var offeringFactionHeadId = Model.ActiveFactions[originatingFactionId].FactionHeadId;
|
||||
var messengerName = Model.Heroes[offeringFactionHeadId].Name;
|
||||
@@ -35,27 +32,18 @@ namespace eagle
|
||||
|
||||
var hostageCount = offer.HostagesOffered.Count + offer.PrisonersOffered.Count;
|
||||
string hostageString = "";
|
||||
if (hostageCount == 1)
|
||||
{
|
||||
if (hostageCount == 1) {
|
||||
hostageString = "a hostage ";
|
||||
}
|
||||
else if (hostageCount > 1)
|
||||
{
|
||||
} else if (hostageCount > 1) {
|
||||
hostageString = "hostages ";
|
||||
}
|
||||
|
||||
var message = $"{messengerName} offers ";
|
||||
if (offer.GoldOffered > 0)
|
||||
{
|
||||
if (offer.GoldOffered > 0) {
|
||||
message += $"{offer.GoldOffered} gold ";
|
||||
|
||||
if (hostageCount > 0)
|
||||
{
|
||||
message += $"and {hostageString} ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hostageCount > 0) { message += $"and {hostageString} "; }
|
||||
} else {
|
||||
message += hostageString;
|
||||
}
|
||||
|
||||
@@ -63,97 +51,93 @@ namespace eagle
|
||||
return message;
|
||||
}
|
||||
|
||||
public AvailableCommand AvailableCommand
|
||||
{
|
||||
public AvailableCommand AvailableCommand {
|
||||
get => _availableCommand;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableCommand = value;
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
PopupInfos = new List<PopupInfo>();
|
||||
}
|
||||
else
|
||||
{
|
||||
PopupInfos = _availableCommand.ResolveRansomOfferCommand.Offers.Select(off => new PopupInfo
|
||||
{
|
||||
} else {
|
||||
PopupInfos = _availableCommand.ResolveRansomOfferCommand.Offers
|
||||
.Select(off => new PopupInfo {
|
||||
titleText = "RansomOffered",
|
||||
mainText = MainText(off),
|
||||
affectedProvinceIds = new List<ProvinceId>()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
SetUpPanel();
|
||||
}
|
||||
}
|
||||
|
||||
public SelectedCommand selectedCommand(DiplomacyOfferStatus resolution) => new SelectedCommand
|
||||
{
|
||||
ResolveRansomOfferCommand = new ResolveRansomOfferSelectedCommand
|
||||
{
|
||||
public SelectedCommand selectedCommand(
|
||||
DiplomacyOfferStatus resolution) => new SelectedCommand {
|
||||
ResolveRansomOfferCommand =
|
||||
new ResolveRansomOfferSelectedCommand {
|
||||
Resolution = resolution,
|
||||
OfferingFactionId = AvailableCommand.ResolveRansomOfferCommand.Offers[DisplayedIndex].OfferingFactionId,
|
||||
RansomOffer = AvailableCommand.ResolveRansomOfferCommand.Offers[DisplayedIndex]
|
||||
OfferingFactionId = AvailableCommand.ResolveRansomOfferCommand
|
||||
.Offers[DisplayedIndex]
|
||||
.OfferingFactionId,
|
||||
RansomOffer =
|
||||
AvailableCommand.ResolveRansomOfferCommand.Offers[DisplayedIndex]
|
||||
}
|
||||
};
|
||||
|
||||
public void AcceptButtonClicked()
|
||||
{
|
||||
public void AcceptButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Accepted));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void RejectButtonClicked()
|
||||
{
|
||||
public void RejectButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Rejected));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void ImprisonButtonClicked()
|
||||
{
|
||||
public void ImprisonButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Imprisoned));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
override protected void SetUpPanel()
|
||||
{
|
||||
override protected void SetUpPanel() {
|
||||
base.SetUpPanel();
|
||||
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
|
||||
if (_availableCommand?.ResolveRansomOfferCommand?.Offers.Count > DisplayedIndex)
|
||||
{
|
||||
if (_availableCommand?.ResolveRansomOfferCommand?.Offers.Count > DisplayedIndex) {
|
||||
var offer = _availableCommand.ResolveRansomOfferCommand.Offers[DisplayedIndex];
|
||||
heroDetailsController.SetHero(Model.Heroes[offer.PrisonerToBeRansomed.PrisonerHeroId], Model);
|
||||
heroDetailsController.SetHero(
|
||||
Model.Heroes[offer.PrisonerToBeRansomed.PrisonerHeroId],
|
||||
Model);
|
||||
var offeringFaction = Model.ActiveFactions[offer.OfferingFactionId];
|
||||
|
||||
var fetcher = GetComponentInParent<AWSResourceFetcher>();
|
||||
FactionHeadshot.texture = fetcher.GetImage(Model.Heroes[offeringFaction.FactionHeadId].ImagePath);
|
||||
FactionHeadshot.texture =
|
||||
fetcher.GetImage(Model.Heroes[offeringFaction.FactionHeadId].ImagePath);
|
||||
|
||||
mapController.OverrideTargetedProvinces = Model.Provinces.Values
|
||||
.Where(pv => pv.RulingFactionId == offeringFaction.Id)
|
||||
mapController.OverrideTargetedProvinces =
|
||||
Model.Provinces.Values.Where(pv => pv.RulingFactionId == offeringFaction.Id)
|
||||
.Select(pv => pv.Id)
|
||||
.ToList();
|
||||
|
||||
exchangedHeroesTable.RowCount = 0;
|
||||
|
||||
var offeringFactionName = Model.FactionName(offer.OfferingFactionId);
|
||||
foreach (var hostage in offer.HostagesOffered)
|
||||
{
|
||||
var row = exchangedHeroesTable.AddRowWithComponent<ExchangedHeroRowController>();
|
||||
foreach (var hostage in offer.HostagesOffered) {
|
||||
var row =
|
||||
exchangedHeroesTable.AddRowWithComponent<ExchangedHeroRowController>();
|
||||
row.SetHostage(Model.Heroes[hostage.HeroId], offeringFactionName);
|
||||
}
|
||||
|
||||
foreach (var prisoner in offer.PrisonersOffered)
|
||||
{
|
||||
var row = exchangedHeroesTable.AddRowWithComponent<ExchangedHeroRowController>();
|
||||
foreach (var prisoner in offer.PrisonersOffered) {
|
||||
var row =
|
||||
exchangedHeroesTable.AddRowWithComponent<ExchangedHeroRowController>();
|
||||
|
||||
var prisonerFactionName = "";
|
||||
if (prisoner.FactionIdForPrisoner != -1)
|
||||
{
|
||||
if (prisoner.FactionIdForPrisoner != -1) {
|
||||
prisonerFactionName = Model.FactionName(prisoner.FactionIdForPrisoner);
|
||||
}
|
||||
row.SetPrisoner(Model.Heroes[prisoner.HeroId], offeringFactionName);
|
||||
|
||||
+27
-36
@@ -5,12 +5,10 @@ using System;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class ResolveTreatyCommandSelector : PopupPanelController
|
||||
{
|
||||
public class ResolveTreatyCommandSelector : PopupPanelController {
|
||||
public Action<SelectedCommand> submissionAction;
|
||||
|
||||
public GameModel Model { get; set; }
|
||||
@@ -21,85 +19,78 @@ namespace eagle
|
||||
public HeroDetailsController heroDetailsController;
|
||||
private AvailableCommand _availableCommand = null;
|
||||
|
||||
private string MainText(TreatyOffer offer)
|
||||
{
|
||||
private string MainText(TreatyOffer offer) {
|
||||
var originatingFactionId = offer.OriginatingFactionId;
|
||||
var messengerHeroId = offer.MessengerHeroId;
|
||||
var messengerName = Model.Heroes[messengerHeroId].Name;
|
||||
return $"{messengerName} brings a treaty proposal from {Model.FactionName(originatingFactionId)}.";
|
||||
}
|
||||
|
||||
public AvailableCommand AvailableCommand
|
||||
{
|
||||
public AvailableCommand AvailableCommand {
|
||||
get => _availableCommand;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableCommand = value;
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
PopupInfos = new List<PopupInfo>();
|
||||
}
|
||||
else
|
||||
{
|
||||
PopupInfos = _availableCommand.ResolveTreatyOfferCommand.Offers.Select(off => new PopupInfo
|
||||
{
|
||||
} else {
|
||||
PopupInfos = _availableCommand.ResolveTreatyOfferCommand.Offers
|
||||
.Select(off => new PopupInfo {
|
||||
titleText = "Treaty Proposed",
|
||||
mainText = MainText(off),
|
||||
affectedProvinceIds = new List<ProvinceId>()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
SetUpPanel();
|
||||
}
|
||||
}
|
||||
|
||||
public SelectedCommand selectedCommand(DiplomacyOfferStatus resolution) => new SelectedCommand
|
||||
{
|
||||
ResolveTreatyOfferCommand = new ResolveTreatyOfferSelectedCommand
|
||||
{
|
||||
public SelectedCommand selectedCommand(DiplomacyOfferStatus resolution) =>
|
||||
new SelectedCommand {
|
||||
ResolveTreatyOfferCommand =
|
||||
new ResolveTreatyOfferSelectedCommand {
|
||||
Resolution = resolution,
|
||||
OriginatingFactionId = AvailableCommand.ResolveTreatyOfferCommand.Offers[DisplayedIndex].OriginatingFactionId
|
||||
OriginatingFactionId = AvailableCommand.ResolveTreatyOfferCommand
|
||||
.Offers[DisplayedIndex]
|
||||
.OriginatingFactionId
|
||||
}
|
||||
};
|
||||
|
||||
public void AcceptButtonClicked()
|
||||
{
|
||||
public void AcceptButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Accepted));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void RejectButtonClicked()
|
||||
{
|
||||
public void RejectButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Rejected));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void ImprisonButtonClicked()
|
||||
{
|
||||
public void ImprisonButtonClicked() {
|
||||
submissionAction(selectedCommand(DiplomacyOfferStatus.Imprisoned));
|
||||
AvailableCommand = null;
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
override protected void SetUpPanel()
|
||||
{
|
||||
override protected void SetUpPanel() {
|
||||
base.SetUpPanel();
|
||||
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
|
||||
if (_availableCommand?.ResolveTreatyOfferCommand?.Offers.Count > DisplayedIndex)
|
||||
{
|
||||
if (_availableCommand?.ResolveTreatyOfferCommand?.Offers.Count > DisplayedIndex) {
|
||||
var offer = _availableCommand.ResolveTreatyOfferCommand.Offers[DisplayedIndex];
|
||||
heroDetailsController.SetHero(Model.Heroes[offer.MessengerHeroId], Model);
|
||||
var offeringFaction = Model.ActiveFactions[offer.OriginatingFactionId];
|
||||
|
||||
var fetcher = GetComponentInParent<AWSResourceFetcher>();
|
||||
FactionHeadshot.texture = fetcher.GetImage(Model.Heroes[offeringFaction.FactionHeadId].ImagePath);
|
||||
FactionHeadshot.texture =
|
||||
fetcher.GetImage(Model.Heroes[offeringFaction.FactionHeadId].ImagePath);
|
||||
|
||||
mapController.OverrideTargetedProvinces = Model.Provinces.Values
|
||||
.Where(pv => pv.RulingFactionId == offeringFaction.Id)
|
||||
mapController.OverrideTargetedProvinces =
|
||||
Model.Provinces.Values.Where(pv => pv.RulingFactionId == offeringFaction.Id)
|
||||
.Select(pv => pv.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
+23
-25
@@ -5,12 +5,10 @@ using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class ResolveTributeCommandSelector : CommandSelector
|
||||
{
|
||||
public class ResolveTributeCommandSelector : CommandSelector {
|
||||
public TMP_Text factionDescription;
|
||||
public TMP_Text goldAmountLabel;
|
||||
public TMP_Text foodAmountLabel;
|
||||
@@ -19,50 +17,49 @@ namespace eagle
|
||||
public Toggle payToggle;
|
||||
public Button nextFactionButton;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ResolveTributeCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ResolveTributeCommand;
|
||||
public override string HeaderString => "Tribute Demanded";
|
||||
public override string CommitButtonString => payToggle.isOn ? "Commit Pay Tribute" : "Commit Refuse to Pay";
|
||||
public override string CommitButtonString =>
|
||||
payToggle.isOn ? "Commit Pay Tribute" : "Commit Refuse to Pay";
|
||||
public override bool EnableCommitButton => !payToggle.isOn || SufficientResources;
|
||||
public override string DisabledCommitButtonReason => "You don't have enough resources to pay";
|
||||
public override string DisabledCommitButtonReason =>
|
||||
"You don't have enough resources to pay";
|
||||
|
||||
private List<TributeAndFaction> _demands;
|
||||
private TributeAndFaction SelectedDemand => _demands[_demandIndex];
|
||||
private bool SufficientResources => ResolveTributeAvailableCommand.AvailableGold >= SelectedDemand.TributeDemanded.Gold
|
||||
&& ResolveTributeAvailableCommand.AvailableFood >= SelectedDemand.TributeDemanded.Food;
|
||||
private bool SufficientResources =>
|
||||
ResolveTributeAvailableCommand.AvailableGold >=
|
||||
SelectedDemand.TributeDemanded.Gold &&
|
||||
ResolveTributeAvailableCommand.AvailableFood >= SelectedDemand.TributeDemanded.Food;
|
||||
|
||||
private int _demandIndex;
|
||||
|
||||
private ResolveTributeAvailableCommand ResolveTributeAvailableCommand => _availableCommand.ResolveTributeCommand;
|
||||
private ResolveTributeAvailableCommand ResolveTributeAvailableCommand =>
|
||||
_availableCommand.ResolveTributeCommand;
|
||||
private ProvinceId ActingProvinceId => ResolveTributeAvailableCommand.ActingProvinceId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ResolveTributeCommand = new ResolveTributeSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
ResolveTributeCommand =
|
||||
new ResolveTributeSelectedCommand {
|
||||
DemandingFactionId = SelectedDemand.DemandingFactionId,
|
||||
Paid = payToggle.isOn
|
||||
}
|
||||
};
|
||||
|
||||
public void NextButtonClicked()
|
||||
{
|
||||
public void NextButtonClicked() {
|
||||
_demandIndex += 1;
|
||||
if (_demandIndex >= _demands.Count)
|
||||
{
|
||||
_demandIndex = 0;
|
||||
}
|
||||
if (_demandIndex >= _demands.Count) { _demandIndex = 0; }
|
||||
DisplayDemand();
|
||||
}
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
_demands = new List<TributeAndFaction>(ResolveTributeAvailableCommand.Demands);
|
||||
_demandIndex = 0;
|
||||
DisplayDemand();
|
||||
}
|
||||
|
||||
private void DisplayDemand()
|
||||
{
|
||||
private void DisplayDemand() {
|
||||
nextFactionButton.gameObject.SetActive(_demands.Count > 1);
|
||||
|
||||
var demandingFaction = _model.MaybeDestroyedFaction(SelectedDemand.DemandingFactionId);
|
||||
@@ -72,7 +69,8 @@ namespace eagle
|
||||
goldAmountLabel.text = SelectedDemand.TributeDemanded.Gold.ToString();
|
||||
foodAmountLabel.text = SelectedDemand.TributeDemanded.Food.ToString();
|
||||
|
||||
var armiesForFaction = _model.Provinces[ActingProvinceId].KnownIncomingArmies.Where(ai => ai.FactionId == SelectedDemand.DemandingFactionId);
|
||||
var armiesForFaction = _model.Provinces[ActingProvinceId].KnownIncomingArmies.Where(
|
||||
ai => ai.FactionId == SelectedDemand.DemandingFactionId);
|
||||
incomingHeroCount.text = SelectedDemand.HeroCount.ToString();
|
||||
incomingTroopsCount.text = SelectedDemand.TroopCount.ToString();
|
||||
|
||||
|
||||
+7
-12
@@ -1,26 +1,21 @@
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class RestCommandSelector : CommandSelector
|
||||
{
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.RestCommand;
|
||||
public class RestCommandSelector : CommandSelector {
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.RestCommand;
|
||||
public override string HeaderString => "Rest";
|
||||
public override string CommitButtonString => "Commit Rest";
|
||||
|
||||
private RestAvailableCommand RestAvailableCommand => _availableCommand.RestCommand;
|
||||
private ProvinceId ActingProvinceId => RestAvailableCommand.ActingProvinceId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
RestSelectedCommand = new RestSelectedCommand()
|
||||
};
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand { RestSelectedCommand = new RestSelectedCommand() };
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
}
|
||||
protected override void SetUpUI() {}
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -3,26 +3,21 @@ using Net.Eagle0.Eagle.Common;
|
||||
using EagleGUIUtils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class ReturnCommandSelector : CommandSelector
|
||||
{
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.ReturnCommand;
|
||||
public class ReturnCommandSelector : CommandSelector {
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.ReturnCommand;
|
||||
public override string HeaderString => "Return to Base";
|
||||
public override string CommitButtonString => "Commit Return";
|
||||
|
||||
private ReturnAvailableCommand ReturnAvailableCommand => _availableCommand.ReturnCommand;
|
||||
private ProvinceId ActingProvinceId => ReturnAvailableCommand.ActingProvinceId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
ReturnSelectedCommand = new ReturnSelectedCommand()
|
||||
};
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand { ReturnSelectedCommand = new ReturnSelectedCommand() };
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
}
|
||||
protected override void SetUpUI() {}
|
||||
}
|
||||
}
|
||||
|
||||
+43
-40
@@ -7,15 +7,15 @@ using EagleGUIUtils;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
using HeroId = Int32;
|
||||
|
||||
public class SendSuppliesCommandSelector : CommandSelector
|
||||
{
|
||||
private ProvinceId SelectedDestinationProvinceId => SendSuppliesAvailableCommand.AvailableDestinationProvinceIds[ToDropdown.value];
|
||||
private ProvinceView SelectedDestinationProvince => _model.Provinces[SelectedDestinationProvinceId];
|
||||
public class SendSuppliesCommandSelector : CommandSelector {
|
||||
private ProvinceId SelectedDestinationProvinceId =>
|
||||
SendSuppliesAvailableCommand.AvailableDestinationProvinceIds[ToDropdown.value];
|
||||
private ProvinceView SelectedDestinationProvince =>
|
||||
_model.Provinces[SelectedDestinationProvinceId];
|
||||
private HeroId SelectedActorId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
public TMP_Dropdown FromDropdown;
|
||||
@@ -28,31 +28,36 @@ namespace eagle
|
||||
public TMP_Text FoodLeft;
|
||||
public HeroDropdownController heroDropdownController;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.SendSuppliesCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.SendSuppliesCommand;
|
||||
public override string HeaderString => "Send Supplies";
|
||||
public override string CommitButtonString => "Commit Send";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedActorId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => SendSuppliesAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
SendSuppliesAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
public override bool WarnOnCommitButton => !SelectedDestinationProvince.RulingFactionId.HasValue || SelectedDestinationProvince.RulingFactionId.Value != _model.PlayerId;
|
||||
public override string CommitWarningText => $"You do not currently occupy {SelectedDestinationProvince.Name}. Are you sure you wish to send supplies there?";
|
||||
public override bool WarnOnCommitButton =>
|
||||
!SelectedDestinationProvince.RulingFactionId.HasValue ||
|
||||
SelectedDestinationProvince.RulingFactionId.Value != _model.PlayerId;
|
||||
public override string CommitWarningText =>
|
||||
$"You do not currently occupy {SelectedDestinationProvince.Name}. Are you sure you wish to send supplies there?";
|
||||
|
||||
private SendSuppliesAvailableCommand SendSuppliesAvailableCommand => _availableCommand.SendSuppliesCommand;
|
||||
private SendSuppliesAvailableCommand SendSuppliesAvailableCommand =>
|
||||
_availableCommand.SendSuppliesCommand;
|
||||
private ProvinceId ActingProvinceId => SendSuppliesAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => SelectedDestinationProvinceId;
|
||||
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
int index = SendSuppliesAvailableCommand.AvailableDestinationProvinceIds.IndexOf(value.Value);
|
||||
if (index != -1)
|
||||
ToDropdown.value = index;
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index =
|
||||
SendSuppliesAvailableCommand.AvailableDestinationProvinceIds.IndexOf(
|
||||
value.Value);
|
||||
if (index != -1) ToDropdown.value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,20 +65,22 @@ namespace eagle
|
||||
public override bool EnableCommitButton => FoodSlider.value > 0 || GoldSlider.value > 0;
|
||||
public override string DisabledCommitButtonReason => "Must send some food or gold";
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
FromDropdown.ClearOptions();
|
||||
FromDropdown.AddOptions(new List<String> { _model.Provinces[ActingProvinceId].Name });
|
||||
|
||||
ToDropdown.ClearOptions();
|
||||
ToDropdown.AddOptions(
|
||||
SendSuppliesAvailableCommand.AvailableDestinationProvinceIds
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
.ToList()
|
||||
);
|
||||
ToDropdown.AddOptions(SendSuppliesAvailableCommand.AvailableDestinationProvinceIds
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList());
|
||||
|
||||
ToDropdown.value = 0;
|
||||
var firstOwned = SendSuppliesAvailableCommand.AvailableDestinationProvinceIds.ToList().FindIndex(pid => _model.Provinces[pid].RulingFactionId.HasValue && _model.Provinces[pid].RulingFactionId.Value == _model.PlayerId);
|
||||
var firstOwned =
|
||||
SendSuppliesAvailableCommand.AvailableDestinationProvinceIds.ToList().FindIndex(
|
||||
pid => _model.Provinces[pid].RulingFactionId.HasValue &&
|
||||
_model.Provinces[pid].RulingFactionId.Value == _model.PlayerId);
|
||||
ToDropdown.value = firstOwned < 0 ? 0 : firstOwned;
|
||||
|
||||
FoodSlider.value = 0;
|
||||
@@ -88,16 +95,14 @@ namespace eagle
|
||||
GoldTaken.text = "0";
|
||||
GoldLeft.text = SendSuppliesAvailableCommand.GoldAvailable.ToString();
|
||||
|
||||
heroDropdownController.AvailableHeroes = SendSuppliesAvailableCommand
|
||||
.AvailableHeroIds
|
||||
.Select(id => _model.Heroes[id])
|
||||
heroDropdownController.AvailableHeroes =
|
||||
SendSuppliesAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id])
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
SendSuppliesCommand = new SendSuppliesSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
SendSuppliesCommand =
|
||||
new SendSuppliesSelectedCommand {
|
||||
Food = (int)FoodSlider.value,
|
||||
Gold = (int)GoldSlider.value,
|
||||
ActingHeroId = SelectedActorId,
|
||||
@@ -105,14 +110,12 @@ namespace eagle
|
||||
}
|
||||
};
|
||||
|
||||
public void GoldSliderChanged(float newValue)
|
||||
{
|
||||
public void GoldSliderChanged(float newValue) {
|
||||
GoldTaken.text = newValue.ToString();
|
||||
GoldLeft.text = (SendSuppliesAvailableCommand.GoldAvailable - newValue).ToString();
|
||||
}
|
||||
|
||||
public void FoodSliderChanged(float newValue)
|
||||
{
|
||||
public void FoodSliderChanged(float newValue) {
|
||||
FoodTaken.text = newValue.ToString();
|
||||
FoodLeft.text = (SendSuppliesAvailableCommand.FoodAvailable - newValue).ToString();
|
||||
}
|
||||
|
||||
+30
-36
@@ -6,67 +6,64 @@ using Net.Eagle0.Eagle.Common;
|
||||
using EagleGUIUtils;
|
||||
using TMPro;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class StartEpidemicCommandSelector : CommandSelector
|
||||
{
|
||||
public class StartEpidemicCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public TMP_Dropdown targetDropdown;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.StartEpidemicCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.StartEpidemicCommand;
|
||||
public override string HeaderString => "Start Plague";
|
||||
public override string CommitButtonString => $"Commit Plague";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => StartEpidemicAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
StartEpidemicAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private StartEpidemicAvailableCommand StartEpidemicAvailableCommand => _availableCommand.StartEpidemicCommand;
|
||||
private StartEpidemicAvailableCommand StartEpidemicAvailableCommand =>
|
||||
_availableCommand.StartEpidemicCommand;
|
||||
private ProvinceId ActingProvinceId => StartEpidemicAvailableCommand.ActingProvinceId;
|
||||
|
||||
private ProvinceId SelectedTargetProvinceId => StartEpidemicAvailableCommand.Options[targetDropdown.value].TargetProvinceId;
|
||||
private ProvinceId SelectedTargetProvinceId =>
|
||||
StartEpidemicAvailableCommand.Options[targetDropdown.value].TargetProvinceId;
|
||||
|
||||
protected override ProvinceId? TargetedProvince
|
||||
{
|
||||
protected override ProvinceId? TargetedProvince {
|
||||
get => SelectedTargetProvinceId;
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
int index = StartEpidemicAvailableCommand.Options.ToList().FindIndex(seo => seo.TargetProvinceId == value.Value);
|
||||
if (index != -1)
|
||||
targetDropdown.value = index;
|
||||
set {
|
||||
if (value.HasValue) {
|
||||
int index = StartEpidemicAvailableCommand.Options.ToList().FindIndex(
|
||||
seo => seo.TargetProvinceId == value.Value);
|
||||
if (index != -1) targetDropdown.value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand
|
||||
{
|
||||
StartEpidemicSelectedCommand = new StartEpidemicSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
StartEpidemicSelectedCommand =
|
||||
new StartEpidemicSelectedCommand {
|
||||
SelectedProvinceId = SelectedTargetProvinceId,
|
||||
ActingHeroId = SelectedHeroId
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = StartEpidemicAvailableCommand
|
||||
.AvailableHeroIds
|
||||
.Select(hid => _model.Heroes[hid])
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
StartEpidemicAvailableCommand.AvailableHeroIds.Select(hid => _model.Heroes[hid])
|
||||
.ToList();
|
||||
|
||||
targetDropdown.ClearOptions();
|
||||
var destinationProvinceNames = StartEpidemicAvailableCommand.Options
|
||||
.Select(opt => opt.TargetProvinceId)
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(_model.Provinces[id], _model.PlayerId.Value))
|
||||
var destinationProvinceNames =
|
||||
StartEpidemicAvailableCommand.Options.Select(opt => opt.TargetProvinceId)
|
||||
.Select(id => GUIUtils.DarkColoredProvinceName(
|
||||
_model.Provinces[id],
|
||||
_model.PlayerId.Value))
|
||||
.ToList();
|
||||
|
||||
targetDropdown.AddOptions(destinationProvinceNames);
|
||||
@@ -74,9 +71,6 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+33
-25
@@ -3,38 +3,44 @@ using Net.Eagle0.Eagle.Api;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using BattalionId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class SuppressBeastsCommandSelector : CommandSelector
|
||||
{
|
||||
public class SuppressBeastsCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public BattalionDropdownController battalionDropdownController;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.SuppressBrigandsCommand;
|
||||
public override string HeaderString => $"Suppress {DisplayNames.Capitalized(DisplayNames.BeastTypeName(BeastType))}";
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.SuppressBrigandsCommand;
|
||||
public override string HeaderString =>
|
||||
$"Suppress {DisplayNames.Capitalized(DisplayNames.BeastTypeName(BeastType))}";
|
||||
public override string CommitButtonString => "Commit Suppression";
|
||||
public override bool WarnOnCommitButton => !SelectedBattalionId.HasValue;
|
||||
public override string CommitWarningText => "You aren't sending a battalion. Your hero may be killed.";
|
||||
public override string CommitWarningText =>
|
||||
"You aren't sending a battalion. Your hero may be killed.";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => SuppressBrigandsAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
SuppressBrigandsAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
public override List<BattalionId> TargetedBattalionIds => SelectedBattalionId.HasValue ? new List<BattalionId> { SelectedBattalionId.Value } : new List<BattalionId>();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) => SuppressBrigandsAvailableCommand.AvailableBattalionIds.Contains(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) => battalionDropdownController.SelectedBattalionId = bid;
|
||||
public override List<BattalionId> TargetedBattalionIds =>
|
||||
SelectedBattalionId.HasValue ? new List<BattalionId> { SelectedBattalionId.Value }
|
||||
: new List<BattalionId>();
|
||||
public override bool BattalionIsTargetable(BattalionId bid) =>
|
||||
SuppressBrigandsAvailableCommand.AvailableBattalionIds.Contains(bid);
|
||||
public override void AddTargetedBattalion(BattalionId bid) =>
|
||||
battalionDropdownController.SelectedBattalionId = bid;
|
||||
|
||||
private SuppressBrigandsAvailableCommand SuppressBrigandsAvailableCommand => _availableCommand.SuppressBrigandsCommand;
|
||||
private SuppressBrigandsAvailableCommand SuppressBrigandsAvailableCommand =>
|
||||
_availableCommand.SuppressBrigandsCommand;
|
||||
private ProvinceId ActingProvinceId => SuppressBrigandsAvailableCommand.ActingProvinceId;
|
||||
|
||||
private Net.Eagle0.Eagle.Common.BeastType BeastType
|
||||
{
|
||||
get
|
||||
{
|
||||
private Net.Eagle0.Eagle.Common.BeastType BeastType {
|
||||
get {
|
||||
if (Province == null) return Net.Eagle0.Eagle.Common.BeastType.Unknown;
|
||||
var beastEvents = Province.KnownEvents.Where(ev => ev.BeastsEvent != null);
|
||||
|
||||
@@ -46,10 +52,13 @@ namespace eagle
|
||||
|
||||
private ProvinceView Province => _model == null ? null : _model.Provinces[ActingProvinceId];
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = SuppressBrigandsAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
battalionDropdownController.AvailableBattalions = SuppressBrigandsAvailableCommand.AvailableBattalionIds
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
SuppressBrigandsAvailableCommand.AvailableHeroIds
|
||||
.Select(id => _model.Heroes[id])
|
||||
.ToList();
|
||||
battalionDropdownController.AvailableBattalions =
|
||||
SuppressBrigandsAvailableCommand.AvailableBattalionIds
|
||||
.Select(id => Province.FullInfo.Battalions.First(b => b.Id == id))
|
||||
.OrderBy(batt => batt.Type)
|
||||
.ToList();
|
||||
@@ -58,10 +67,9 @@ namespace eagle
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
private BattalionId? SelectedBattalionId => battalionDropdownController.SelectedBattalionId;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
SuppressBrigandsCommand = new SuppressBrigandsSelectedCommand()
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
SuppressBrigandsCommand =
|
||||
new SuppressBrigandsSelectedCommand() {
|
||||
HeroId = SelectedHeroId,
|
||||
BattalionId = SelectedBattalionId
|
||||
}
|
||||
|
||||
+19
-21
@@ -3,49 +3,47 @@ using System.Linq;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class SwearBrotherhoodCommandSelector : CommandSelector
|
||||
{
|
||||
public class SwearBrotherhoodCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
public HeroDetailsController heroDetails;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.SwearBrotherhoodCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.SwearBrotherhoodCommand;
|
||||
public override string HeaderString => "Swear Brotherhood with Hero";
|
||||
public override string CommitButtonString => "Commit Oath";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => SwearBrotherhoodAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
SwearBrotherhoodAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private SwearBrotherhoodAvailableCommand SwearBrotherhoodAvailableCommand => _availableCommand.SwearBrotherhoodCommand;
|
||||
private SwearBrotherhoodAvailableCommand SwearBrotherhoodAvailableCommand =>
|
||||
_availableCommand.SwearBrotherhoodCommand;
|
||||
private ProvinceId ActingProvinceId => SwearBrotherhoodAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
heroDropdownController.AvailableHeroes = SwearBrotherhoodAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
protected override void SetUpUI() {
|
||||
heroDropdownController.AvailableHeroes =
|
||||
SwearBrotherhoodAvailableCommand.AvailableHeroIds
|
||||
.Select(id => _model.Heroes[id])
|
||||
.ToList();
|
||||
|
||||
heroDropdownController.SelectedHeroIdUpdated = () => HeroDropdownChanged();
|
||||
|
||||
HeroDropdownChanged();
|
||||
}
|
||||
|
||||
void HeroDropdownChanged()
|
||||
{
|
||||
heroDetails.SetHero(_model.Heroes[SelectedHeroId], _model);
|
||||
}
|
||||
void HeroDropdownChanged() { heroDetails.SetHero(_model.Heroes[SelectedHeroId], _model); }
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
SwearBrotherhoodCommand = new SwearBrotherhoodSelectedCommand
|
||||
{
|
||||
NewBrotherHeroId = SelectedHeroId
|
||||
}
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
SwearBrotherhoodCommand =
|
||||
new SwearBrotherhoodSelectedCommand { NewBrotherHeroId = SelectedHeroId }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+17
-18
@@ -4,12 +4,10 @@ using Net.Eagle0.Eagle.Common;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class TradeCommandSelector : CommandSelector
|
||||
{
|
||||
public class TradeCommandSelector : CommandSelector {
|
||||
public TMP_Text buyPrice;
|
||||
public TMP_Text sellPrice;
|
||||
public Slider slider;
|
||||
@@ -17,18 +15,20 @@ namespace eagle
|
||||
public TMP_Text foodText;
|
||||
public TMP_Text description;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.TradeCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.TradeCommand;
|
||||
public override string HeaderString => "Trade";
|
||||
public override string CommitButtonString => IsBuy ? "Commit Buy" : "Commit Sell";
|
||||
|
||||
private TradeAvailableCommand TradeCommand => _availableCommand.TradeCommand;
|
||||
private ProvinceId ActingProvinceId => TradeCommand.ActingProvinceId;
|
||||
|
||||
private int MaxFood => TradeCommand.FoodAvailable + (int)Math.Floor(TradeCommand.GoldAvailable / TradeCommand.FoodBuyPrice);
|
||||
private int MaxFood =>
|
||||
TradeCommand.FoodAvailable +
|
||||
(int)Math.Floor(TradeCommand.GoldAvailable / TradeCommand.FoodBuyPrice);
|
||||
private int FoodAmount => (int)slider.value;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
protected override void SetUpUI() {
|
||||
slider.minValue = 0;
|
||||
slider.maxValue = MaxFood;
|
||||
slider.value = TradeCommand.FoodAvailable;
|
||||
@@ -44,26 +44,25 @@ namespace eagle
|
||||
|
||||
private bool IsBuy => FoodAmount > TradeCommand.FoodAvailable;
|
||||
private int NetFood => FoodAmount - TradeCommand.FoodAvailable;
|
||||
private int NetGold => IsBuy ? -(int)Math.Ceiling(NetFood * TradeCommand.FoodBuyPrice) : -(int)Math.Ceiling(NetFood * TradeCommand.FoodSellPrice);
|
||||
private int NetGold => IsBuy ? -(int)Math.Ceiling(NetFood * TradeCommand.FoodBuyPrice)
|
||||
: -(int)Math.Ceiling(NetFood * TradeCommand.FoodSellPrice);
|
||||
private int GoldAmount => TradeCommand.GoldAvailable + NetGold;
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
TradeCommand = new TradeSelectedCommand
|
||||
{
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
TradeCommand =
|
||||
new TradeSelectedCommand {
|
||||
Amount = Math.Abs(FoodAmount - TradeCommand.FoodAvailable),
|
||||
TradeType = IsBuy
|
||||
? TradeSelectedCommand.Types.TradeType.BuyFood
|
||||
TradeType = IsBuy ? TradeSelectedCommand.Types.TradeType.BuyFood
|
||||
: TradeSelectedCommand.Types.TradeType.SellFood
|
||||
}
|
||||
};
|
||||
|
||||
public void SetTextFields()
|
||||
{
|
||||
public void SetTextFields() {
|
||||
goldText.text = GoldAmount.ToString();
|
||||
foodText.text = FoodAmount.ToString();
|
||||
|
||||
description.text = IsBuy ? $"Buying {NetFood} food for {-NetGold} gold" : $"Selling {-NetFood} food for {NetGold} gold";
|
||||
description.text = IsBuy ? $"Buying {NetFood} food for {-NetGold} gold"
|
||||
: $"Selling {-NetFood} food for {NetGold} gold";
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-16
@@ -2,42 +2,39 @@
|
||||
using System.Linq;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = System.Int32;
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class TrainCommandSelector : CommandSelector
|
||||
{
|
||||
public class TrainCommandSelector : CommandSelector {
|
||||
public HeroDropdownController heroDropdownController;
|
||||
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.TrainCommand;
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.TrainCommand;
|
||||
public override string HeaderString => "Train";
|
||||
public override string CommitButtonString => "Commit Train";
|
||||
|
||||
public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
|
||||
public override bool HeroIsTargetable(HeroId heroId) => TrainAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) => heroDropdownController.SelectedHeroId = heroId;
|
||||
public override bool HeroIsTargetable(HeroId heroId) =>
|
||||
TrainAvailableCommand.AvailableHeroIds.Contains(heroId);
|
||||
public override void AddTargetedHero(HeroId heroId) =>
|
||||
heroDropdownController.SelectedHeroId = heroId;
|
||||
|
||||
private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;
|
||||
|
||||
private TrainAvailableCommand TrainAvailableCommand => _availableCommand.TrainCommand;
|
||||
private ProvinceId ActingProvinceId => TrainAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
var heroes = TrainAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
protected override void SetUpUI() {
|
||||
var heroes =
|
||||
TrainAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
|
||||
heroDropdownController.AvailableHeroes = heroes;
|
||||
|
||||
heroDropdownController.SelectedHeroId = TrainAvailableCommand.RecommendedHeroId;
|
||||
}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
TrainCommand = new TrainSelectedCommand
|
||||
{
|
||||
ActingHeroId = SelectedHeroId
|
||||
}
|
||||
public override SelectedCommand Command => new SelectedCommand {
|
||||
TrainCommand = new TrainSelectedCommand { ActingHeroId = SelectedHeroId }
|
||||
};
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -1,26 +1,21 @@
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class TravelCommandSelector : CommandSelector
|
||||
{
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType => AvailableCommand.SealedValueOneofCase.TravelCommand;
|
||||
public class TravelCommandSelector : CommandSelector {
|
||||
public override AvailableCommand.SealedValueOneofCase CommandType =>
|
||||
AvailableCommand.SealedValueOneofCase.TravelCommand;
|
||||
public override string HeaderString => "Travel";
|
||||
public override string CommitButtonString => "Commit Travel";
|
||||
|
||||
private TravelAvailableCommand TravelAvailableCommand => _availableCommand.TravelCommand;
|
||||
private ProvinceId ActingProvinceId => TravelAvailableCommand.ActingProvinceId;
|
||||
|
||||
protected override void SetUpUI()
|
||||
{
|
||||
}
|
||||
protected override void SetUpUI() {}
|
||||
|
||||
public override SelectedCommand Command => new SelectedCommand
|
||||
{
|
||||
TravelCommand = new TravelSelectedCommand()
|
||||
};
|
||||
public override SelectedCommand Command =>
|
||||
new SelectedCommand { TravelCommand = new TravelSelectedCommand() };
|
||||
}
|
||||
}
|
||||
+27
-23
@@ -7,53 +7,57 @@ using System;
|
||||
using UnityEngine.Events;
|
||||
using System.Linq;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using BattalionId = Int32;
|
||||
|
||||
public class BattalionDropdownController : MonoBehaviour
|
||||
{
|
||||
public class BattalionDropdownController : MonoBehaviour {
|
||||
private List<BattalionView> _availableBattalions;
|
||||
public List<BattalionView> AvailableBattalions
|
||||
{
|
||||
public List<BattalionView> AvailableBattalions {
|
||||
get => _availableBattalions;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableBattalions = new List<BattalionView>(value);
|
||||
|
||||
var dropdown = GetComponent<TMP_Dropdown>();
|
||||
|
||||
dropdown.ClearOptions();
|
||||
dropdown.AddOptions(new List<TMP_Dropdown.OptionData> { new TMP_Dropdown.OptionData { text = "None" } });
|
||||
dropdown.AddOptions(new List<TMP_Dropdown.OptionData> {
|
||||
new TMP_Dropdown.OptionData { text = "None" }
|
||||
});
|
||||
dropdown.AddOptions(AvailableBattalions.Select(BattalionOption).ToList());
|
||||
dropdown.value = Math.Min(1, AvailableBattalions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public BattalionId? SelectedBattalionId
|
||||
{
|
||||
get => GetComponent<TMP_Dropdown>().value == 0 ? null : (BattalionId?)(AvailableBattalions[GetComponent<TMP_Dropdown>().value - 1].Id);
|
||||
set => GetComponent<TMP_Dropdown>().value = AvailableBattalions.FindIndex(h => h.Id == value) + 1;
|
||||
public BattalionId? SelectedBattalionId {
|
||||
get => GetComponent<TMP_Dropdown>().value == 0
|
||||
? null
|
||||
: (BattalionId?)(
|
||||
AvailableBattalions[GetComponent<TMP_Dropdown>().value - 1]
|
||||
.Id);
|
||||
set => GetComponent<TMP_Dropdown>().value =
|
||||
AvailableBattalions.FindIndex(h => h.Id == value) + 1;
|
||||
}
|
||||
|
||||
public UnityEvent SelectedBattalionIdUpdated;
|
||||
|
||||
public void DropdownUpdated(int newValue)
|
||||
{
|
||||
gameObject.GetComponentInParent<EagleGameController>().GetComponentInChildren<HeroesAndBattalionsPanelController>().UpdateBattalionSelections();
|
||||
public void DropdownUpdated(int newValue) {
|
||||
gameObject.GetComponentInParent<EagleGameController>()
|
||||
.GetComponentInChildren<HeroesAndBattalionsPanelController>()
|
||||
.UpdateBattalionSelections();
|
||||
|
||||
if (SelectedBattalionIdUpdated != null) SelectedBattalionIdUpdated.Invoke();
|
||||
}
|
||||
|
||||
private TMP_Dropdown.OptionData BattalionOption(BattalionView bv)
|
||||
{
|
||||
var texture = gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(bv.Type);
|
||||
return new TMP_Dropdown.OptionData
|
||||
{
|
||||
image = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)),
|
||||
private TMP_Dropdown.OptionData BattalionOption(BattalionView bv) {
|
||||
var texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(bv.Type);
|
||||
return new TMP_Dropdown.OptionData {
|
||||
image = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f)),
|
||||
text = $"{bv.Name} ({bv.Size})"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+107
-141
@@ -8,14 +8,12 @@ using System;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using BattalionId = Int32;
|
||||
using static Net.Eagle0.Eagle.Api.Command.Util.SuitableBattalions.Types;
|
||||
|
||||
public class EventBasedUnitSelector : MonoBehaviour
|
||||
{
|
||||
public class EventBasedUnitSelector : MonoBehaviour {
|
||||
public GameObject availableHeroesContent;
|
||||
public GameObject availableBattalionsContent;
|
||||
public GameObject selectedUnitsContent;
|
||||
@@ -31,30 +29,27 @@ namespace eagle
|
||||
|
||||
public int BattalionCount => SelectedActingUnits.Where(u => u.BattalionId.HasValue).Count();
|
||||
|
||||
private EagleCommonTextures textures => gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
private EagleCommonTextures textures =>
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
|
||||
public struct MaybeHeroAndBattalion
|
||||
{
|
||||
public struct MaybeHeroAndBattalion {
|
||||
public HeroId? heroId;
|
||||
public BattalionView battalion;
|
||||
|
||||
public BattalionId? BattalionId => battalion == null ? (BattalionId?)null : battalion.Id;
|
||||
public BattalionId? BattalionId =>
|
||||
battalion == null ? (BattalionId?)null : battalion.Id;
|
||||
}
|
||||
public List<MaybeHeroAndBattalion> SelectedIds = new List<MaybeHeroAndBattalion>();
|
||||
|
||||
private List<HeroId> _allHeroIds;
|
||||
private List<BattalionView> _orderedBattalions;
|
||||
|
||||
public List<CombatUnit> SelectedActingUnits
|
||||
{
|
||||
get
|
||||
{
|
||||
public List<CombatUnit> SelectedActingUnits {
|
||||
get {
|
||||
var cus = new List<CombatUnit>();
|
||||
if (SelectedIds.Exists(sid => !sid.heroId.HasValue)) return cus;
|
||||
for (int i = 0; i < SelectedIds.Count; i++)
|
||||
{
|
||||
cus.Add(new CombatUnit
|
||||
{
|
||||
for (int i = 0; i < SelectedIds.Count; i++) {
|
||||
cus.Add(new CombatUnit {
|
||||
HeroId = SelectedIds[i].heroId.Value,
|
||||
BattalionId = SelectedIds[i].BattalionId,
|
||||
FactionId = _model.PlayerId.Value
|
||||
@@ -63,47 +58,52 @@ namespace eagle
|
||||
return cus;
|
||||
}
|
||||
}
|
||||
public bool UnitsAreValid => SelectedIds.Count > 0
|
||||
&& SelectedIds.TrueForAll(sid => sid.heroId.HasValue);
|
||||
public string InvalidUnitsReason => SelectedIds.Count < 1 ? "No units were selected" : "Each battalion must have a hero";
|
||||
public bool UnitsAreValid => SelectedIds.Count > 0 &&
|
||||
SelectedIds.TrueForAll(sid => sid.heroId.HasValue);
|
||||
public string InvalidUnitsReason => SelectedIds.Count < 1
|
||||
? "No units were selected"
|
||||
: "Each battalion must have a hero";
|
||||
|
||||
public List<HeroId> HeroIdsLeadingInappropriateUnits => SelectedActingUnits.Where(u => u.BattalionId.HasValue && SuitableBattalions[u.HeroId].Find(bws => bws.BattalionId == u.BattalionId.Value).Level == SuitabilityLevel.Restrictive)
|
||||
public List<HeroId> HeroIdsLeadingInappropriateUnits =>
|
||||
SelectedActingUnits
|
||||
.Where(u => u.BattalionId.HasValue &&
|
||||
SuitableBattalions[u.HeroId]
|
||||
.Find(bws => bws.BattalionId ==
|
||||
u.BattalionId.Value)
|
||||
.Level == SuitabilityLevel.Restrictive)
|
||||
.Select(u => u.HeroId)
|
||||
.ToList();
|
||||
|
||||
public bool HeroIsTargetable(HeroId heroId) => AvailableHeroIds.Contains(heroId) || SelectedActingUnits.Select(u => u.HeroId).Contains(heroId);
|
||||
public void AddTargetedHero(HeroId heroId)
|
||||
{
|
||||
public bool HeroIsTargetable(HeroId heroId) =>
|
||||
AvailableHeroIds.Contains(heroId) ||
|
||||
SelectedActingUnits.Select(u => u.HeroId).Contains(heroId);
|
||||
public void AddTargetedHero(HeroId heroId) {
|
||||
var index = AvailableHeroIds.IndexOf(heroId);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
availableHeroButtonClicked(index);
|
||||
}
|
||||
if (index != -1) { availableHeroButtonClicked(index); }
|
||||
}
|
||||
|
||||
public void RemoveTargetedHero(HeroId heroId) => selectedHeroClicked(SelectedIds.FindIndex(cu => cu.heroId == heroId));
|
||||
public void RemoveTargetedHero(HeroId heroId) =>
|
||||
selectedHeroClicked(SelectedIds.FindIndex(cu => cu.heroId == heroId));
|
||||
|
||||
public bool BattalionIsTargetable(BattalionId bid) => AvailableBattalions.Where(batt => batt.Id == bid).Count() > 0 || SelectedActingUnits.Select(u => u.BattalionId).Contains(bid);
|
||||
public void AddTargetedBattalion(BattalionId bid)
|
||||
{
|
||||
public bool BattalionIsTargetable(BattalionId bid) =>
|
||||
AvailableBattalions.Where(batt => batt.Id == bid).Count() > 0 ||
|
||||
SelectedActingUnits.Select(u => u.BattalionId).Contains(bid);
|
||||
public void AddTargetedBattalion(BattalionId bid) {
|
||||
var index = AvailableBattalions.FindIndex(batt => batt.Id == bid);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
availableBattalionButtonClicked(index);
|
||||
}
|
||||
if (index != -1) { availableBattalionButtonClicked(index); }
|
||||
}
|
||||
|
||||
public void RemoveTargetedBattalion(BattalionId bid) => selectedBattalionClicked(SelectedIds.FindIndex(cu => cu.BattalionId == bid));
|
||||
public void RemoveTargetedBattalion(BattalionId bid) =>
|
||||
selectedBattalionClicked(SelectedIds.FindIndex(cu => cu.BattalionId == bid));
|
||||
|
||||
public void SetUpUnits(
|
||||
GameModel model,
|
||||
List<HeroId> availableHeroIds,
|
||||
List<BattalionView> orderedBattalions,
|
||||
Dictionary<HeroId, List<BattalionIdWithSuitability>> suitableBattalions,
|
||||
List<CombatUnit> recommendedUnits)
|
||||
{
|
||||
List<CombatUnit> recommendedUnits) {
|
||||
_model = model;
|
||||
_allHeroIds = availableHeroIds;
|
||||
_orderedBattalions = orderedBattalions;
|
||||
@@ -125,9 +125,12 @@ namespace eagle
|
||||
Dictionary<HeroId, List<BattalionIdWithSuitability>> SuitableBattalions;
|
||||
List<CombatUnit> RecommendedUnits;
|
||||
|
||||
private GameObject instantiateInTable(GameObject prefab, Transform tableContent)
|
||||
{
|
||||
var newRow = Instantiate(prefab, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), tableContent);
|
||||
private GameObject instantiateInTable(GameObject prefab, Transform tableContent) {
|
||||
var newRow = Instantiate(
|
||||
prefab,
|
||||
new Vector3(0, 0, 0),
|
||||
new Quaternion(0, 0, 0, 0),
|
||||
tableContent);
|
||||
|
||||
// FIXME: I don't know why this reset of the z-position is necessary
|
||||
var position = newRow.GetComponent<RectTransform>().anchoredPosition3D;
|
||||
@@ -137,97 +140,82 @@ namespace eagle
|
||||
return newRow;
|
||||
}
|
||||
|
||||
private void SetUpTables()
|
||||
{
|
||||
private void SetUpTables() {
|
||||
AvailableHeroIds.OrderBy(hid => _allHeroIds.IndexOf(hid));
|
||||
AvailableBattalions.OrderBy(b => _orderedBattalions.IndexOf(b));
|
||||
var oddColor = availableHeroRow.GetComponent<UnityEngine.UI.Image>().color;
|
||||
oddColor.a = 0;
|
||||
|
||||
foreach (Transform row in availableHeroesContent.transform)
|
||||
{
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
foreach (Transform row in availableHeroesContent.transform) { Destroy(row.gameObject); }
|
||||
var parentTransform = availableHeroesContent.transform;
|
||||
for (int i = 0; i < AvailableHeroIds.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < AvailableHeroIds.Count; i++) {
|
||||
var hid = AvailableHeroIds[i];
|
||||
var hero = _model.Heroes[hid];
|
||||
|
||||
var newRow = instantiateInTable(availableHeroRow, parentTransform).GetComponent<UnitSelectorHeroRowController>();
|
||||
var newRow = instantiateInTable(availableHeroRow, parentTransform)
|
||||
.GetComponent<UnitSelectorHeroRowController>();
|
||||
newRow.Hero = hero;
|
||||
|
||||
var index = i;
|
||||
newRow.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(() => availableHeroButtonClicked(index));
|
||||
newRow.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
() => availableHeroButtonClicked(index));
|
||||
newRow.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor;
|
||||
}
|
||||
if (i % 2 == 1) { newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor; }
|
||||
}
|
||||
|
||||
foreach (Transform row in selectedUnitsContent.transform)
|
||||
{
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
foreach (Transform row in selectedUnitsContent.transform) { Destroy(row.gameObject); }
|
||||
parentTransform = selectedUnitsContent.transform;
|
||||
|
||||
var idsCount = SelectedIds.Count;
|
||||
for (int i = 0; i < idsCount; i++)
|
||||
{
|
||||
var newRow = instantiateInTable(selectedUnitRow, parentTransform).GetComponent<SelectedUnitRowController>();
|
||||
for (int i = 0; i < idsCount; i++) {
|
||||
var newRow = instantiateInTable(selectedUnitRow, parentTransform)
|
||||
.GetComponent<SelectedUnitRowController>();
|
||||
var buttons = newRow.GetComponentsInChildren<Button>();
|
||||
|
||||
var heroId = SelectedIds[i].heroId;
|
||||
var battalion = SelectedIds[i].battalion;
|
||||
var appropriate = heroId.HasValue &&
|
||||
(battalion == null || SuitableBattalions[heroId.Value].Find(bws => bws.BattalionId == battalion.Id).Level != SuitabilityLevel.Restrictive);
|
||||
(battalion == null ||
|
||||
SuitableBattalions[heroId.Value]
|
||||
.Find(bws => bws.BattalionId == battalion.Id)
|
||||
.Level != SuitabilityLevel.Restrictive);
|
||||
|
||||
var index = i;
|
||||
|
||||
if (heroId is HeroId hid)
|
||||
{
|
||||
if (heroId is HeroId hid) {
|
||||
var hero = _model.Heroes[hid];
|
||||
newRow.Hero = hero;
|
||||
newRow.Appropriate = appropriate;
|
||||
newRow.HeroClickDetector = () => selectedHeroClicked(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
newRow.Hero = null;
|
||||
}
|
||||
|
||||
newRow.Battalion = battalion;
|
||||
newRow.BattalionClickDetector = () => selectedBattalionClicked(index);
|
||||
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor;
|
||||
}
|
||||
if (i % 2 == 1) { newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor; }
|
||||
}
|
||||
|
||||
foreach (Transform row in availableBattalionsContent.transform)
|
||||
{
|
||||
foreach (Transform row in availableBattalionsContent.transform) {
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
parentTransform = availableBattalionsContent.transform;
|
||||
for (int i = 0; i < AvailableBattalions.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < AvailableBattalions.Count; i++) {
|
||||
var battalion = AvailableBattalions[i];
|
||||
|
||||
var newRow = instantiateInTable(availableBattalionsRow.gameObject, parentTransform).GetComponent<BattalionRowController>();
|
||||
var newRow = instantiateInTable(availableBattalionsRow.gameObject, parentTransform)
|
||||
.GetComponent<BattalionRowController>();
|
||||
newRow.Battalion = battalion;
|
||||
|
||||
var index = i;
|
||||
|
||||
newRow.GetComponent<TableRowClickDetector>().onClick.AddListener(() => availableBattalionButtonClicked(index));
|
||||
newRow.GetComponent<TableRowClickDetector>().onClick.AddListener(
|
||||
() => availableBattalionButtonClicked(index));
|
||||
newRow.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor;
|
||||
}
|
||||
if (i % 2 == 1) { newRow.GetComponent<UnityEngine.UI.Image>().color = oddColor; }
|
||||
}
|
||||
|
||||
heroesAndBattalionsPanelController.UpdateTables();
|
||||
@@ -235,20 +223,12 @@ namespace eagle
|
||||
selectionChanged.Invoke();
|
||||
}
|
||||
|
||||
public void availableHeroButtonClicked(int index)
|
||||
{
|
||||
public void availableHeroButtonClicked(int index) {
|
||||
var hid = AvailableHeroIds[index];
|
||||
var chosenIndex = SelectedIds.FindIndex(sid => !sid.heroId.HasValue);
|
||||
if (chosenIndex == -1)
|
||||
{
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion
|
||||
{
|
||||
heroId = hid,
|
||||
battalion = null
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (chosenIndex == -1) {
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion { heroId = hid, battalion = null });
|
||||
} else {
|
||||
var sid = SelectedIds[chosenIndex];
|
||||
sid.heroId = hid;
|
||||
SelectedIds[chosenIndex] = sid;
|
||||
@@ -259,20 +239,12 @@ namespace eagle
|
||||
SetUpTables();
|
||||
}
|
||||
|
||||
public void availableBattalionButtonClicked(int index)
|
||||
{
|
||||
public void availableBattalionButtonClicked(int index) {
|
||||
var batt = AvailableBattalions[index];
|
||||
var chosenIndex = SelectedIds.FindIndex(sid => sid.battalion == null);
|
||||
if (chosenIndex == -1)
|
||||
{
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion
|
||||
{
|
||||
heroId = null,
|
||||
battalion = batt
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (chosenIndex == -1) {
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion { heroId = null, battalion = batt });
|
||||
} else {
|
||||
var sid = SelectedIds[chosenIndex];
|
||||
sid.battalion = batt;
|
||||
SelectedIds[chosenIndex] = sid;
|
||||
@@ -283,19 +255,15 @@ namespace eagle
|
||||
SetUpTables();
|
||||
}
|
||||
|
||||
public void selectedHeroClicked(int index)
|
||||
{
|
||||
public void selectedHeroClicked(int index) {
|
||||
var heroId = SelectedIds[index].heroId;
|
||||
if (heroId.HasValue)
|
||||
{
|
||||
if (heroId.HasValue) {
|
||||
AvailableHeroIds.Add(heroId.Value);
|
||||
|
||||
if (SelectedIds[index].battalion != null)
|
||||
{
|
||||
SelectedIds[index] = new MaybeHeroAndBattalion { battalion = SelectedIds[index].battalion };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedIds[index].battalion != null) {
|
||||
SelectedIds[index] =
|
||||
new MaybeHeroAndBattalion { battalion = SelectedIds[index].battalion };
|
||||
} else {
|
||||
SelectedIds.RemoveAt(index);
|
||||
}
|
||||
|
||||
@@ -304,19 +272,15 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public void selectedBattalionClicked(int index)
|
||||
{
|
||||
public void selectedBattalionClicked(int index) {
|
||||
var battalion = SelectedIds[index].battalion;
|
||||
if (battalion != null)
|
||||
{
|
||||
if (battalion != null) {
|
||||
AvailableBattalions.Add(battalion);
|
||||
|
||||
if (SelectedIds[index].heroId.HasValue)
|
||||
{
|
||||
SelectedIds[index] = new MaybeHeroAndBattalion { heroId = SelectedIds[index].heroId };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedIds[index].heroId.HasValue) {
|
||||
SelectedIds[index] =
|
||||
new MaybeHeroAndBattalion { heroId = SelectedIds[index].heroId };
|
||||
} else {
|
||||
SelectedIds.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
@@ -325,24 +289,29 @@ namespace eagle
|
||||
SetUpTables();
|
||||
}
|
||||
|
||||
public void recommendedConfigClicked()
|
||||
{
|
||||
SelectedIds.Select(sid => sid.heroId).Where(hid => hid.HasValue).ToList().ForEach(hid => AvailableHeroIds.Add(hid.Value));
|
||||
SelectedIds.Select(sid => sid.battalion).Where(bid => bid != null).ToList().ForEach(batt => AvailableBattalions.Add(batt));
|
||||
public void recommendedConfigClicked() {
|
||||
SelectedIds.Select(sid => sid.heroId)
|
||||
.Where(hid => hid.HasValue)
|
||||
.ToList()
|
||||
.ForEach(hid => AvailableHeroIds.Add(hid.Value));
|
||||
SelectedIds.Select(sid => sid.battalion)
|
||||
.Where(bid => bid != null)
|
||||
.ToList()
|
||||
.ForEach(batt => AvailableBattalions.Add(batt));
|
||||
SelectedIds.Clear();
|
||||
|
||||
foreach (var cu in RecommendedUnits)
|
||||
{
|
||||
var recommendedBattalion = cu.BattalionId.HasValue ? _orderedBattalions.First(batt => batt.Id == cu.BattalionId) : null;
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion
|
||||
{
|
||||
foreach (var cu in RecommendedUnits) {
|
||||
var recommendedBattalion =
|
||||
cu.BattalionId.HasValue
|
||||
? _orderedBattalions.First(batt => batt.Id == cu.BattalionId)
|
||||
: null;
|
||||
SelectedIds.Add(new MaybeHeroAndBattalion {
|
||||
heroId = cu.HeroId,
|
||||
battalion = recommendedBattalion
|
||||
});
|
||||
AvailableHeroIds.Remove(cu.HeroId);
|
||||
|
||||
if (recommendedBattalion != null)
|
||||
{
|
||||
if (recommendedBattalion != null) {
|
||||
AvailableBattalions.Remove(recommendedBattalion);
|
||||
}
|
||||
}
|
||||
@@ -353,9 +322,6 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+28
-36
@@ -7,12 +7,10 @@ using System;
|
||||
using EagleGUIUtils;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
|
||||
public class HeroDropdownController : MonoBehaviour
|
||||
{
|
||||
public class HeroDropdownController : MonoBehaviour {
|
||||
private TMP_Dropdown Dropdown => gameObject.GetComponent<TMP_Dropdown>();
|
||||
public RawImage HeadshotImage;
|
||||
public bool showCondition = true;
|
||||
@@ -22,24 +20,19 @@ namespace eagle
|
||||
public string ConditionName = "VIG";
|
||||
|
||||
private List<HeroView> _availableHeroes;
|
||||
public List<HeroView> AvailableHeroes
|
||||
{
|
||||
public List<HeroView> AvailableHeroes {
|
||||
get => _availableHeroes;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableHeroes = new List<HeroView>(value);
|
||||
Dropdown.ClearOptions();
|
||||
Dropdown.AddOptions(
|
||||
_availableHeroes.Select(HeroOption).ToList());
|
||||
Dropdown.AddOptions(_availableHeroes.Select(HeroOption).ToList());
|
||||
SetHeadshot();
|
||||
}
|
||||
}
|
||||
|
||||
public HeroId SelectedHeroId
|
||||
{
|
||||
public HeroId SelectedHeroId {
|
||||
get => AvailableHeroes[Dropdown.value].Id;
|
||||
set
|
||||
{
|
||||
set {
|
||||
Dropdown.value = AvailableHeroes.FindIndex(h => h.Id == value);
|
||||
DropdownUpdated(Dropdown.value);
|
||||
}
|
||||
@@ -47,30 +40,23 @@ namespace eagle
|
||||
|
||||
public Action SelectedHeroIdUpdated;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Dropdown.onValueChanged.AddListener(DropdownUpdated);
|
||||
}
|
||||
void Start() { Dropdown.onValueChanged.AddListener(DropdownUpdated); }
|
||||
|
||||
private void SetHeadshot()
|
||||
{
|
||||
private void SetHeadshot() {
|
||||
var fetcher = GetComponentInParent<AWSResourceFetcher>();
|
||||
if (fetcher != null)
|
||||
{
|
||||
if (fetcher != null) {
|
||||
var imagePath = AvailableHeroes[Dropdown.value].ImagePath;
|
||||
if (!string.IsNullOrEmpty(imagePath))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(imagePath)) {
|
||||
HeadshotImage.texture = fetcher.GetImage(imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DropdownUpdated(int newValue)
|
||||
{
|
||||
void DropdownUpdated(int newValue) {
|
||||
var egc = gameObject.GetComponentInParent<EagleGameController>();
|
||||
if (egc != null)
|
||||
{
|
||||
egc.GetComponentInChildren<HeroesAndBattalionsPanelController>().UpdateHeroSelections();
|
||||
if (egc != null) {
|
||||
egc.GetComponentInChildren<HeroesAndBattalionsPanelController>()
|
||||
.UpdateHeroSelections();
|
||||
}
|
||||
|
||||
SetHeadshot();
|
||||
@@ -78,17 +64,23 @@ namespace eagle
|
||||
if (SelectedHeroIdUpdated != null) SelectedHeroIdUpdated.Invoke();
|
||||
}
|
||||
|
||||
private TMP_Dropdown.OptionData HeroOption(HeroView hv)
|
||||
{
|
||||
private TMP_Dropdown.OptionData HeroOption(HeroView hv) {
|
||||
var texture = textures.Profession(hv.Profession);
|
||||
var text = showCondition ? $"{hv.Name} ({GUIUtils.ConditionString(ConditionAccessor(hv), ConditionName)})" : hv.Name;
|
||||
return new TMP_Dropdown.OptionData
|
||||
{
|
||||
image = texture == null ? null : Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)),
|
||||
var text =
|
||||
showCondition
|
||||
? $"{hv.Name} ({GUIUtils.ConditionString(ConditionAccessor(hv), ConditionName)})"
|
||||
: hv.Name;
|
||||
return new TMP_Dropdown.OptionData {
|
||||
image = texture == null ? null
|
||||
: Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f)),
|
||||
text = text
|
||||
};
|
||||
}
|
||||
|
||||
private EagleCommonTextures textures => gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
private EagleCommonTextures textures =>
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-16
@@ -1,29 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class CommandWarningPanelController : PopupPanelController
|
||||
{
|
||||
public void SetWarning(string title, string text)
|
||||
{
|
||||
PopupInfos = new List<PopupInfo>
|
||||
{
|
||||
new PopupInfo
|
||||
{
|
||||
public class CommandWarningPanelController : PopupPanelController {
|
||||
public void SetWarning(string title, string text) {
|
||||
PopupInfos = new List<PopupInfo> { new PopupInfo {
|
||||
titleText = title,
|
||||
mainText = text,
|
||||
affectedProvinceIds = new List<ProvinceId>()
|
||||
}
|
||||
};
|
||||
} };
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
public void ClearWarning()
|
||||
{
|
||||
if (PopupInfos.Count > 0)
|
||||
{
|
||||
public void ClearWarning() {
|
||||
if (PopupInfos.Count > 0) {
|
||||
PopupInfos.Clear();
|
||||
SetUpPanel();
|
||||
}
|
||||
|
||||
@@ -5,12 +5,10 @@ using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Api.Command.Util;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class DisplayNames
|
||||
{
|
||||
public static readonly Dictionary<Profession, string> ProfessionNames = new Dictionary<Profession, string>
|
||||
{
|
||||
namespace eagle {
|
||||
public class DisplayNames {
|
||||
public static readonly Dictionary<Profession, string> ProfessionNames =
|
||||
new Dictionary<Profession, string> {
|
||||
{ Profession.NoProfession, "None" },
|
||||
{ Profession.Engineer, "Engineer" },
|
||||
{ Profession.Mage, "Mage" },
|
||||
@@ -20,8 +18,8 @@ namespace eagle
|
||||
{ Profession.Champion, "Champion" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<Profession, string> ShortProfessionNames = new Dictionary<Profession, string>
|
||||
{
|
||||
public static readonly Dictionary<Profession, string> ShortProfessionNames =
|
||||
new Dictionary<Profession, string> {
|
||||
{ Profession.NoProfession, "None" },
|
||||
{ Profession.Engineer, "Engr" },
|
||||
{ Profession.Mage, "Mage" },
|
||||
@@ -31,8 +29,8 @@ namespace eagle
|
||||
{ Profession.Champion, "Chmp" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<BattalionTypeId, string> LongBattalionTypeNames = new Dictionary<BattalionTypeId, string>
|
||||
{
|
||||
public static readonly Dictionary<BattalionTypeId, string> LongBattalionTypeNames =
|
||||
new Dictionary<BattalionTypeId, string> {
|
||||
{ BattalionTypeId.LightInfantry, "Light Infantry" },
|
||||
{ BattalionTypeId.HeavyInfantry, "Heavy Infantry" },
|
||||
{ BattalionTypeId.LightCavalry, "Light Cavalry" },
|
||||
@@ -40,8 +38,8 @@ namespace eagle
|
||||
{ BattalionTypeId.Longbowmen, "Longbowmen" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<BattalionTypeId, string> ShortBattalionTypeNames = new Dictionary<BattalionTypeId, string>
|
||||
{
|
||||
public static readonly Dictionary<BattalionTypeId, string> ShortBattalionTypeNames =
|
||||
new Dictionary<BattalionTypeId, string> {
|
||||
{ BattalionTypeId.LightInfantry, "L Infantry" },
|
||||
{ BattalionTypeId.HeavyInfantry, "H Infantry" },
|
||||
{ BattalionTypeId.LightCavalry, "L Cavalry" },
|
||||
@@ -49,16 +47,16 @@ namespace eagle
|
||||
{ BattalionTypeId.Longbowmen, "Longbowmen" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<ProvinceOrderType, string> ProvinceOrderTypeNames = new Dictionary<ProvinceOrderType, string>
|
||||
{
|
||||
public static readonly Dictionary<ProvinceOrderType, string> ProvinceOrderTypeNames =
|
||||
new Dictionary<ProvinceOrderType, string> {
|
||||
{ ProvinceOrderType.Develop, "Develop" },
|
||||
{ ProvinceOrderType.Expand, "Expand" },
|
||||
{ ProvinceOrderType.Mobilize, "Mobilize" },
|
||||
{ ProvinceOrderType.Entrust, "Entrust" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<CapturedHeroOption, string> CapturedHeroOptionNames = new Dictionary<CapturedHeroOption, string>
|
||||
{
|
||||
public static readonly Dictionary<CapturedHeroOption, string> CapturedHeroOptionNames =
|
||||
new Dictionary<CapturedHeroOption, string> {
|
||||
{ CapturedHeroOption.RecruitCapturedHeroOption, "Recruit" },
|
||||
{ CapturedHeroOption.ImprisonCapturedHeroOption, "Imprison" },
|
||||
{ CapturedHeroOption.ExileCapturedHeroOption, "Exile" },
|
||||
@@ -66,24 +64,17 @@ namespace eagle
|
||||
{ CapturedHeroOption.ReturnCapturedHeroOption, "Return" }
|
||||
};
|
||||
|
||||
public static string PrisonerManagementTypeName(PrisonerManagementOption option)
|
||||
{
|
||||
switch (option.SealedValueCase)
|
||||
{
|
||||
public static string PrisonerManagementTypeName(PrisonerManagementOption option) {
|
||||
switch (option.SealedValueCase) {
|
||||
case PrisonerManagementOption.SealedValueOneofCase.Execute: return "Execute";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string QuestStringFromName(string name, Quest quest, GameModel model)
|
||||
{
|
||||
if (quest == null)
|
||||
{
|
||||
return $"There is nothing you can do for {name} right now.";
|
||||
}
|
||||
public static string QuestStringFromName(string name, Quest quest, GameModel model) {
|
||||
if (quest == null) { return $"There is nothing you can do for {name} right now."; }
|
||||
|
||||
switch (quest.DetailsCase)
|
||||
{
|
||||
switch (quest.DetailsCase) {
|
||||
case Quest.DetailsOneofCase.DefeatFactionQuest:
|
||||
return $"{name} hates {model.FactionName(quest.DefeatFactionQuest.TargetFactionId)} and will be pleased if you defeat them in battle.";
|
||||
|
||||
@@ -122,17 +113,10 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public static string ShortQuestString(Quest quest, GameModel model) {
|
||||
if (quest == null) { return $"There is nothing you can do"; }
|
||||
|
||||
|
||||
public static string ShortQuestString(Quest quest, GameModel model)
|
||||
{
|
||||
if (quest == null)
|
||||
{
|
||||
return $"There is nothing you can do";
|
||||
}
|
||||
|
||||
switch (quest.DetailsCase)
|
||||
{
|
||||
switch (quest.DetailsCase) {
|
||||
case Quest.DetailsOneofCase.DefeatFactionQuest:
|
||||
return $"Defeat {model.FactionName(quest.DefeatFactionQuest.TargetFactionId)}";
|
||||
|
||||
@@ -166,25 +150,20 @@ namespace eagle
|
||||
case Quest.DetailsOneofCase.TreatyCountQuest:
|
||||
return $"Have treaties with {quest.TreatyCountQuest.TreatyCount} factions";
|
||||
|
||||
default:
|
||||
return $"Crosby hasn't gotten to it yet";
|
||||
default: return $"Crosby hasn't gotten to it yet";
|
||||
}
|
||||
}
|
||||
|
||||
public static string QuestString(ExpandedUnaffiliatedHero euh, GameModel model)
|
||||
{
|
||||
public static string QuestString(ExpandedUnaffiliatedHero euh, GameModel model) {
|
||||
return QuestStringFromName(euh.Hero.Name, euh.Quest, model);
|
||||
}
|
||||
|
||||
public static string RecruitmentStatusString(string name, RecruitmentInfo recruitmentInfo)
|
||||
{
|
||||
switch (recruitmentInfo.Status)
|
||||
{
|
||||
public static string RecruitmentStatusString(string name, RecruitmentInfo recruitmentInfo) {
|
||||
switch (recruitmentInfo.Status) {
|
||||
case RecruitmentStatus.LowPrestige:
|
||||
return $"You need more prestige before you can seek {name}'s favor.";
|
||||
|
||||
case RecruitmentStatus.WouldJoin:
|
||||
return $"{name} would already gladly join you.";
|
||||
case RecruitmentStatus.WouldJoin: return $"{name} would already gladly join you.";
|
||||
|
||||
case RecruitmentStatus.NotDivined:
|
||||
return $"You need to divine to learn {name}'s wishes.";
|
||||
@@ -201,140 +180,96 @@ namespace eagle
|
||||
case RecruitmentStatus.Traveler:
|
||||
return $"{name} is unlikely to stay here long enough to impress with a quest.";
|
||||
|
||||
case RecruitmentStatus.Sworn:
|
||||
return $"{name} is dedicated to another faction.";
|
||||
case RecruitmentStatus.Sworn: return $"{name} is dedicated to another faction.";
|
||||
}
|
||||
|
||||
return $"Unknown!";
|
||||
}
|
||||
|
||||
public static string ShortRecruitmentStatusString(RecruitmentInfo recruitmentInfo)
|
||||
{
|
||||
switch (recruitmentInfo.Status)
|
||||
{
|
||||
case RecruitmentStatus.LowPrestige:
|
||||
return $"Not enough prestige";
|
||||
public static string ShortRecruitmentStatusString(RecruitmentInfo recruitmentInfo) {
|
||||
switch (recruitmentInfo.Status) {
|
||||
case RecruitmentStatus.LowPrestige: return $"Not enough prestige";
|
||||
|
||||
case RecruitmentStatus.WouldJoin:
|
||||
return $"Ready to join";
|
||||
case RecruitmentStatus.WouldJoin: return $"Ready to join";
|
||||
|
||||
case RecruitmentStatus.NotDivined:
|
||||
return $"Not divined";
|
||||
case RecruitmentStatus.NotDivined: return $"Not divined";
|
||||
|
||||
case RecruitmentStatus.Outlaw:
|
||||
return $"Outlaw";
|
||||
case RecruitmentStatus.Outlaw: return $"Outlaw";
|
||||
|
||||
case RecruitmentStatus.Exile:
|
||||
return $"Exile";
|
||||
case RecruitmentStatus.Exile: return $"Exile";
|
||||
|
||||
case RecruitmentStatus.Prisoner:
|
||||
return $"Prisoner";
|
||||
case RecruitmentStatus.Prisoner: return $"Prisoner";
|
||||
|
||||
case RecruitmentStatus.Traveler:
|
||||
return $"Traveler";
|
||||
case RecruitmentStatus.Traveler: return $"Traveler";
|
||||
|
||||
case RecruitmentStatus.Sworn:
|
||||
return $"Dedicated to another faction";
|
||||
case RecruitmentStatus.Sworn: return $"Dedicated to another faction";
|
||||
}
|
||||
|
||||
return $"Unknown!";
|
||||
}
|
||||
|
||||
public static string QuestTypeString(Quest quest)
|
||||
{
|
||||
switch (quest.DetailsCase)
|
||||
{
|
||||
case Quest.DetailsOneofCase.DefeatFactionQuest:
|
||||
return "Attack Faction";
|
||||
case Quest.DetailsOneofCase.DismissSpecificVassalQuest:
|
||||
return "Dismiss Vassal";
|
||||
case Quest.DetailsOneofCase.ImproveAgricultureQuest:
|
||||
return "Improve Agriculture";
|
||||
case Quest.DetailsOneofCase.ImproveEconomyQuest:
|
||||
return "Improve Economy";
|
||||
public static string QuestTypeString(Quest quest) {
|
||||
switch (quest.DetailsCase) {
|
||||
case Quest.DetailsOneofCase.DefeatFactionQuest: return "Attack Faction";
|
||||
case Quest.DetailsOneofCase.DismissSpecificVassalQuest: return "Dismiss Vassal";
|
||||
case Quest.DetailsOneofCase.ImproveAgricultureQuest: return "Improve Agriculture";
|
||||
case Quest.DetailsOneofCase.ImproveEconomyQuest: return "Improve Economy";
|
||||
case Quest.DetailsOneofCase.ImproveInfrastructureQuest:
|
||||
return "Improve Infrastructure";
|
||||
case Quest.DetailsOneofCase.UpgradeBattalionQuest:
|
||||
return "Great Battalion";
|
||||
case Quest.DetailsOneofCase.GrandArmyQuest:
|
||||
return "Grand Army";
|
||||
case Quest.DetailsOneofCase.SpecificExpansionQuest:
|
||||
return "Expand to Province";
|
||||
case Quest.DetailsOneofCase.WealthQuest:
|
||||
return "Accumulate Wealth";
|
||||
case Quest.DetailsOneofCase.TreatyWithFactionQuest:
|
||||
return "Treaty with Faction";
|
||||
case Quest.DetailsOneofCase.TreatyCountQuest:
|
||||
return "Treaty Count";
|
||||
case Quest.DetailsOneofCase.UpgradeBattalionQuest: return "Great Battalion";
|
||||
case Quest.DetailsOneofCase.GrandArmyQuest: return "Grand Army";
|
||||
case Quest.DetailsOneofCase.SpecificExpansionQuest: return "Expand to Province";
|
||||
case Quest.DetailsOneofCase.WealthQuest: return "Accumulate Wealth";
|
||||
case Quest.DetailsOneofCase.TreatyWithFactionQuest: return "Treaty with Faction";
|
||||
case Quest.DetailsOneofCase.TreatyCountQuest: return "Treaty Count";
|
||||
}
|
||||
|
||||
throw new ArgumentException($"unknown quest {quest}");
|
||||
}
|
||||
|
||||
public static string MonthString(int month)
|
||||
{
|
||||
public static string MonthString(int month) {
|
||||
return new DateTime(777, month, 1).ToString("MMMM", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static string MonthString(Date date)
|
||||
{
|
||||
return new DateTime(date.Year, date.Month, 1).ToString("MMMM", CultureInfo.InvariantCulture);
|
||||
public static string MonthString(Date date) {
|
||||
return new DateTime(date.Year, date.Month, 1)
|
||||
.ToString("MMMM", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static string DateString(Date date)
|
||||
{
|
||||
return $"{MonthString(date)} {date.Year}";
|
||||
}
|
||||
public static string DateString(Date date) { return $"{MonthString(date)} {date.Year}"; }
|
||||
|
||||
public static string UnaffiliatedHeroStatus(UnaffiliatedHero.Types.Type status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
public static string UnaffiliatedHeroStatus(UnaffiliatedHero.Types.Type status) {
|
||||
switch (status) {
|
||||
case UnaffiliatedHero.Types.Type.Prisoner: return "Prisoner";
|
||||
|
||||
case UnaffiliatedHero.Types.Type.Prisoner:
|
||||
return "Prisoner";
|
||||
case UnaffiliatedHero.Types.Type.Traveler: return "Traveler";
|
||||
|
||||
case UnaffiliatedHero.Types.Type.Traveler:
|
||||
return "Traveler";
|
||||
case UnaffiliatedHero.Types.Type.Resident: return "Resident";
|
||||
|
||||
case UnaffiliatedHero.Types.Type.Resident:
|
||||
return "Resident";
|
||||
|
||||
case UnaffiliatedHero.Types.Type.Outlaw:
|
||||
return "Outlaw";
|
||||
case UnaffiliatedHero.Types.Type.Outlaw: return "Outlaw";
|
||||
|
||||
case UnaffiliatedHero.Types.Type.Unknown:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("Unknown free hero status");
|
||||
default: throw new ArgumentOutOfRangeException("Unknown free hero status");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ControlWeatherTypeName(ControlWeatherType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ControlWeatherType.ControlWeatherStartBlizzard:
|
||||
return "Start Blizzard";
|
||||
public static string ControlWeatherTypeName(ControlWeatherType type) {
|
||||
switch (type) {
|
||||
case ControlWeatherType.ControlWeatherStartBlizzard: return "Start Blizzard";
|
||||
|
||||
case ControlWeatherType.ControlWeatherEndBlizzard:
|
||||
return "End Blizzard";
|
||||
case ControlWeatherType.ControlWeatherEndBlizzard: return "End Blizzard";
|
||||
|
||||
case ControlWeatherType.ControlWeatherStartDrought:
|
||||
return "Start Drought";
|
||||
case ControlWeatherType.ControlWeatherStartDrought: return "Start Drought";
|
||||
|
||||
case ControlWeatherType.ControlWeatherEndDrought:
|
||||
return "End Drought";
|
||||
case ControlWeatherType.ControlWeatherEndDrought: return "End Drought";
|
||||
|
||||
case ControlWeatherType.ControlWeatherUnknown:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("Unknown control weather type");
|
||||
default: throw new ArgumentOutOfRangeException("Unknown control weather type");
|
||||
}
|
||||
}
|
||||
|
||||
public static string BeastTypeName(BeastType beastType)
|
||||
{
|
||||
return beastType switch
|
||||
{
|
||||
public static string BeastTypeName(BeastType beastType) {
|
||||
return beastType switch {
|
||||
BeastType.Brigands => "brigands",
|
||||
BeastType.Wolves => "wolves",
|
||||
BeastType.Tigers => "tigers",
|
||||
@@ -363,30 +298,22 @@ namespace eagle
|
||||
};
|
||||
}
|
||||
|
||||
public static string Capitalized(string str)
|
||||
{
|
||||
public static string Capitalized(string str) {
|
||||
if (String.IsNullOrEmpty(str)) return str;
|
||||
else if (str.Length == 1) return str.ToUpper();
|
||||
else return char.ToUpper(str[0]) + str.Substring(1);
|
||||
else if (str.Length == 1)
|
||||
return str.ToUpper();
|
||||
else
|
||||
return char.ToUpper(str[0]) + str.Substring(1);
|
||||
}
|
||||
|
||||
public static string ListString(IList<String> strings)
|
||||
{
|
||||
if (strings.Count == 1)
|
||||
{
|
||||
public static string ListString(IList<String> strings) {
|
||||
if (strings.Count == 1) {
|
||||
return strings[0];
|
||||
}
|
||||
else if (strings.Count == 2)
|
||||
{
|
||||
} else if (strings.Count == 2) {
|
||||
return $"{strings[0]} and {strings[1]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
string str = "";
|
||||
for (int i = 0; i < strings.Count - 1; i++)
|
||||
{
|
||||
str += strings[i] + ", ";
|
||||
}
|
||||
for (int i = 0; i < strings.Count - 1; i++) { str += strings[i] + ", "; }
|
||||
str += "and " + strings[strings.Count - 1];
|
||||
|
||||
return str;
|
||||
|
||||
+33
-68
@@ -8,12 +8,10 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class DominionPanelController : MonoBehaviour
|
||||
{
|
||||
public class DominionPanelController : MonoBehaviour {
|
||||
public TMP_Text label;
|
||||
public EventBasedTable table;
|
||||
|
||||
@@ -21,8 +19,7 @@ namespace eagle
|
||||
public MapController mapController;
|
||||
public Toggle onToggle;
|
||||
|
||||
enum SortKey
|
||||
{
|
||||
enum SortKey {
|
||||
None = 0,
|
||||
Support = 1,
|
||||
Commanders = 2,
|
||||
@@ -37,8 +34,8 @@ namespace eagle
|
||||
Castles = 11,
|
||||
}
|
||||
|
||||
Dictionary<SortKey, Func<ProvinceView, int>> sortFuncs = new Dictionary<SortKey, Func<ProvinceView, int>>
|
||||
{
|
||||
Dictionary<SortKey, Func<ProvinceView, int>> sortFuncs =
|
||||
new Dictionary<SortKey, Func<ProvinceView, int>> {
|
||||
{ SortKey.Support, p => p.FullInfo.Support.Stat },
|
||||
{ SortKey.Commanders, p => p.FullInfo.RulingFactionHeroIds.Count },
|
||||
{ SortKey.Battalions, p => p.FullInfo.Battalions.Count },
|
||||
@@ -56,72 +53,55 @@ namespace eagle
|
||||
private bool ascending = false;
|
||||
|
||||
private GameModel _model;
|
||||
public GameModel Model
|
||||
{
|
||||
set
|
||||
{
|
||||
public GameModel Model {
|
||||
set {
|
||||
_model = value;
|
||||
SetUpTable();
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceUpdate()
|
||||
{
|
||||
SetUpTable();
|
||||
}
|
||||
public void ForceUpdate() { SetUpTable(); }
|
||||
|
||||
private List<ProvinceView> SortedProvinces()
|
||||
{
|
||||
private List<ProvinceView> SortedProvinces() {
|
||||
var unsorted = _model.Provinces.Values.Where(p => p.RulingFactionId == _model.PlayerId);
|
||||
|
||||
if (currentSortKey == SortKey.None)
|
||||
{
|
||||
return unsorted.OrderBy(p => p.Name).ToList();
|
||||
}
|
||||
if (currentSortKey == SortKey.None) { return unsorted.OrderBy(p => p.Name).ToList(); }
|
||||
|
||||
var sortFunc = sortFuncs[currentSortKey];
|
||||
|
||||
if (ascending)
|
||||
{
|
||||
if (ascending) {
|
||||
return unsorted.OrderBy(sortFunc).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return unsorted.OrderByDescending(sortFunc).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
void SetUpTable()
|
||||
{
|
||||
void SetUpTable() {
|
||||
var provinces = SortedProvinces();
|
||||
|
||||
table.RowCount = provinces.Count;
|
||||
|
||||
for (int i = 0; i < provinces.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < provinces.Count; i++) {
|
||||
var province = provinces[i];
|
||||
var hasCommands = _model.AvailableCommandsForProvince(province.Id).Any();
|
||||
table.ComponentAt<DominionTableRowController>(i).Set(province.Id, _model, mapController.SelectedProvinceId == province.Id, hasCommands);
|
||||
table.ComponentAt<DominionTableRowController>(i).Set(
|
||||
province.Id,
|
||||
_model,
|
||||
mapController.SelectedProvinceId == province.Id,
|
||||
hasCommands);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(int key)
|
||||
{
|
||||
public void Sort(int key) {
|
||||
SortKey newKey = (SortKey)key;
|
||||
|
||||
if (newKey == currentSortKey)
|
||||
{
|
||||
if (!ascending)
|
||||
{
|
||||
if (newKey == currentSortKey) {
|
||||
if (!ascending) {
|
||||
ascending = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
currentSortKey = SortKey.None;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
currentSortKey = newKey;
|
||||
ascending = false;
|
||||
}
|
||||
@@ -130,46 +110,31 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
currentSortKey = SortKey.None;
|
||||
ascending = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
void Update() {}
|
||||
|
||||
}
|
||||
|
||||
public void ProvinceHovered(ProvinceId? pid)
|
||||
{
|
||||
for (int i = 0; i < table.RowCount; i++)
|
||||
{
|
||||
public void ProvinceHovered(ProvinceId? pid) {
|
||||
for (int i = 0; i < table.RowCount; i++) {
|
||||
table.ComponentAt<DominionTableRowController>(i).ShadeOff();
|
||||
}
|
||||
if (pid is ProvinceId provinceId)
|
||||
{
|
||||
if (pid is ProvinceId provinceId) {
|
||||
var index = SortedProvinces().FindIndex(p => p.Id == provinceId);
|
||||
if (index != -1)
|
||||
{
|
||||
table.ComponentAt<DominionTableRowController>(index).ShadeOn();
|
||||
}
|
||||
if (index != -1) { table.ComponentAt<DominionTableRowController>(index).ShadeOn(); }
|
||||
}
|
||||
}
|
||||
|
||||
public void RowClicked(int provinceId)
|
||||
{
|
||||
mapController.SelectedProvinceId = provinceId;
|
||||
}
|
||||
public void RowClicked(int provinceId) { mapController.SelectedProvinceId = provinceId; }
|
||||
|
||||
public void RowHovered(int provinceId)
|
||||
{
|
||||
public void RowHovered(int provinceId) {
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId> { provinceId };
|
||||
}
|
||||
|
||||
public void RowUnhovered()
|
||||
{
|
||||
public void RowUnhovered() {
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-8
@@ -4,27 +4,32 @@ using System.Threading.Tasks;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Shardok.Common;
|
||||
|
||||
namespace eagle0
|
||||
{
|
||||
namespace eagle0 {
|
||||
using PlayerId = Int32;
|
||||
using GameId = Int64;
|
||||
using ProvinceId = Int32;
|
||||
using static Net.Eagle0.Eagle.Api.ShardokPlacementCommands.Types;
|
||||
using static Net.Eagle0.Eagle.Api.UpdateStreamRequest.Types;
|
||||
|
||||
public interface EagleClientInterface
|
||||
{
|
||||
public interface EagleClientInterface {
|
||||
PlayerId? PlayerId { get; }
|
||||
GameId GameId { get; }
|
||||
|
||||
Task<Boolean> RegisterForUpdates(
|
||||
Action<UpdateStreamResponse, Grpc.Core.StatusCode> repeatedCallback,
|
||||
int knownHistoryCount,
|
||||
List<ShardokViewStatus> shardokViewStatuses); // calls back with null if interrupted
|
||||
List<ShardokViewStatus>
|
||||
shardokViewStatuses); // calls back with null if interrupted
|
||||
void UnregisterForUpdates();
|
||||
Task<PostCommandResponse> PostCommand(long token, ProvinceId provinceId, SelectedCommand command);
|
||||
Task<PostCommandResponse> PostShardokCommand(string gameId, Int32 playerId, Int64 token, Int32 index);
|
||||
Task<PostCommandResponse> PostShardokPlacementCommands(string gameId, Int32 playerId, List<ShardokPlacementCommand> placementCommands, Int64 token);
|
||||
Task<PostCommandResponse>
|
||||
PostCommand(long token, ProvinceId provinceId, SelectedCommand command);
|
||||
Task<PostCommandResponse>
|
||||
PostShardokCommand(string gameId, Int32 playerId, Int64 token, Int32 index);
|
||||
Task<PostCommandResponse> PostShardokPlacementCommands(
|
||||
string gameId,
|
||||
Int32 playerId,
|
||||
List<ShardokPlacementCommand> placementCommands,
|
||||
Int64 token);
|
||||
Task<HexMap> GetHexMapAsync(string mapName);
|
||||
HexMap GetHexMap(string mapName); // FIXME: get rid of synchronous version
|
||||
}
|
||||
|
||||
+14
-19
@@ -3,8 +3,7 @@ using System.Linq;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using UnityEngine;
|
||||
|
||||
public class EagleCommonTextures : MonoBehaviour
|
||||
{
|
||||
public class EagleCommonTextures : MonoBehaviour {
|
||||
public List<Texture2D> battalionTextures;
|
||||
public List<Texture2D> professionTextures;
|
||||
public Texture2D training;
|
||||
@@ -12,31 +11,27 @@ public class EagleCommonTextures : MonoBehaviour
|
||||
|
||||
public Texture2D noProfessionTexture;
|
||||
|
||||
public Texture2D BattalionType(BattalionTypeId type)
|
||||
{
|
||||
public Texture2D BattalionType(BattalionTypeId type) { return battalionTextures[(int)type]; }
|
||||
|
||||
public Texture2D BattalionType(
|
||||
Net.Eagle0.Shardok.Api.BattalionView.Types.BattalionTypeId type) {
|
||||
return battalionTextures[(int)type];
|
||||
}
|
||||
|
||||
public Texture2D BattalionType(Net.Eagle0.Shardok.Api.BattalionView.Types.BattalionTypeId type)
|
||||
{
|
||||
return battalionTextures[(int)type];
|
||||
}
|
||||
|
||||
public Texture2D Profession(Profession profession)
|
||||
{
|
||||
if (profession == Net.Eagle0.Eagle.Common.Profession.NoProfession) return professionTextures.Last();
|
||||
public Texture2D Profession(Profession profession) {
|
||||
if (profession == Net.Eagle0.Eagle.Common.Profession.NoProfession)
|
||||
return professionTextures.Last();
|
||||
return professionTextures[(int)profession];
|
||||
}
|
||||
|
||||
public Texture2D Profession(Net.Eagle0.Shardok.Api.HeroView.Types.ProfessionSpecificInfo.Types.Profession profession)
|
||||
{
|
||||
if (profession == Net.Eagle0.Shardok.Api.HeroView.Types.ProfessionSpecificInfo.Types.Profession.NoProfession) return professionTextures.Last();
|
||||
public Texture2D Profession(Net.Eagle0.Shardok.Api.HeroView.Types.ProfessionSpecificInfo.Types
|
||||
.Profession profession) {
|
||||
if (profession == Net.Eagle0.Shardok.Api.HeroView.Types.ProfessionSpecificInfo.Types
|
||||
.Profession.NoProfession)
|
||||
return professionTextures.Last();
|
||||
return professionTextures[(int)profession];
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
|
||||
+142
-219
@@ -11,16 +11,14 @@ using eagle0;
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using GameId = Int64;
|
||||
using FactionId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
using HeroId = Int32;
|
||||
using CommandType = AvailableCommand.SealedValueOneofCase;
|
||||
|
||||
public class EagleGameController : MonoBehaviour
|
||||
{
|
||||
public class EagleGameController : MonoBehaviour {
|
||||
public Camera mainCamera;
|
||||
public TextMeshProUGUI roundStatusLabel;
|
||||
|
||||
@@ -66,22 +64,20 @@ namespace eagle
|
||||
public Canvas ShardokCanvas;
|
||||
|
||||
private KeyValuePair<ProvinceId, OneProvinceAvailableCommands> NextActiveProvinceKeyPair =>
|
||||
Model.AvailableCommandsByProvince.First(kvp => kvp.Key == Model.SuggestedProvinceId);
|
||||
Model.AvailableCommandsByProvince.First(
|
||||
kvp => kvp.Key == Model.SuggestedProvinceId);
|
||||
|
||||
struct GameInfo
|
||||
{
|
||||
struct GameInfo {
|
||||
public FactionId playerId { get; }
|
||||
public GameId gameId { get; }
|
||||
|
||||
public GameInfo(FactionId playerId, GameId gameId)
|
||||
{
|
||||
public GameInfo(FactionId playerId, GameId gameId) {
|
||||
this.playerId = playerId;
|
||||
this.gameId = gameId;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
gameIdButton.GetComponentInChildren<Text>().text = "";
|
||||
mapController.TargetedProvincesChangedCallback = MapControllerChangedTarget;
|
||||
mapController.HoveredProvinceChangedCallback = MapControllerChangedHover;
|
||||
@@ -90,103 +86,78 @@ namespace eagle
|
||||
dominionPanelController.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void MapControllerChangedTarget(List<ProvinceId> newTarget)
|
||||
{
|
||||
if (commandPanelController.Selector != null)
|
||||
{
|
||||
void MapControllerChangedTarget(List<ProvinceId> newTarget) {
|
||||
if (commandPanelController.Selector != null) {
|
||||
commandPanelController.Selector.TargetedProvinces = newTarget;
|
||||
focusInfoPanelController.UpdateTables();
|
||||
heroesAndBattalionsPanelController.UpdateTables();
|
||||
}
|
||||
}
|
||||
|
||||
void MapControllerChangedHover(ProvinceId? newHover)
|
||||
{
|
||||
void MapControllerChangedHover(ProvinceId? newHover) {
|
||||
dominionPanelController.ProvinceHovered(newHover);
|
||||
focusInfoPanelController.ProvinceHovered(newHover);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (newModel != null)
|
||||
{
|
||||
SwapModel();
|
||||
}
|
||||
void Update() {
|
||||
if (newModel != null) { SwapModel(); }
|
||||
|
||||
if (Model != null)
|
||||
{
|
||||
if (commandPanelController.Selector == null)
|
||||
{
|
||||
if (Model.AvailableCommandsByProvince.Count > 0 && Model.AvailableCommandsByProvince.ContainsKey(0))
|
||||
{
|
||||
if (Model != null) {
|
||||
if (commandPanelController.Selector == null) {
|
||||
if (Model.AvailableCommandsByProvince.Count > 0 &&
|
||||
Model.AvailableCommandsByProvince.ContainsKey(0)) {
|
||||
mapController.ProvincesWithCommands = new List<ProvinceId>();
|
||||
}
|
||||
else
|
||||
{
|
||||
mapController.ProvincesWithCommands = Model.AvailableCommandsByProvince.Keys.ToList();
|
||||
} else {
|
||||
mapController.ProvincesWithCommands =
|
||||
Model.AvailableCommandsByProvince.Keys.ToList();
|
||||
}
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
}
|
||||
else
|
||||
{
|
||||
mapController.TargetedProvinces = commandPanelController.Selector.TargetedProvinces;
|
||||
} else {
|
||||
mapController.TargetedProvinces =
|
||||
commandPanelController.Selector.TargetedProvinces;
|
||||
mapController.ProvincesWithCommands = new List<ProvinceId>();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetButtonUp("Cancel"))
|
||||
{
|
||||
if (Input.GetButtonUp("Cancel")) {
|
||||
HandleQuit();
|
||||
}
|
||||
else if (Input.GetButtonUp("Windowed Mode"))
|
||||
{
|
||||
} else if (Input.GetButtonUp("Windowed Mode")) {
|
||||
#if UNITY_EDITOR
|
||||
// do nothing
|
||||
#else
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
#endif
|
||||
}
|
||||
else if (Input.GetButtonUp("Toggle Dominion Table"))
|
||||
{
|
||||
} else if (Input.GetButtonUp("Toggle Dominion Table")) {
|
||||
dominionViewToggle.isOn = !dominionViewToggle.isOn;
|
||||
}
|
||||
}
|
||||
|
||||
void OnApplicationPause(bool pause)
|
||||
{
|
||||
void OnApplicationPause(bool pause) {
|
||||
#if !UNITY_EDITOR
|
||||
if (ModelUpdater == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (pause)
|
||||
{
|
||||
if (ModelUpdater == null) { return; }
|
||||
if (pause) {
|
||||
ModelUpdater.StopListeningForUpdates();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ModelUpdater.StartListeningForUpdates();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
}
|
||||
void OnApplicationQuit() {}
|
||||
|
||||
void OnApplicationFocus(bool focus)
|
||||
{
|
||||
}
|
||||
void OnApplicationFocus(bool focus) {}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
}
|
||||
void OnPlayModeStateChanged(PlayModeStateChange state) {}
|
||||
#endif
|
||||
|
||||
public void SetUpGame(long gameId, int? playerId, EagleConnection eagleConnection)
|
||||
{
|
||||
var oneGameClient = new RemoteEagleClient(gameId, eagleConnection.EagleGrpcClient, eagleConnection.Credentials, playerId, EagleConnection.EagleCancellationToken);
|
||||
public void SetUpGame(long gameId, int? playerId, EagleConnection eagleConnection) {
|
||||
var oneGameClient = new RemoteEagleClient(
|
||||
gameId,
|
||||
eagleConnection.EagleGrpcClient,
|
||||
eagleConnection.Credentials,
|
||||
playerId,
|
||||
EagleConnection.EagleCancellationToken);
|
||||
ModelUpdater = new GameModelUpdater(oneGameClient, eagleConnection.PlayerName);
|
||||
|
||||
EagleConnection = eagleConnection;
|
||||
@@ -194,7 +165,8 @@ namespace eagle
|
||||
|
||||
ModelUpdater.UpdateAction = ModelUpdated;
|
||||
|
||||
ModelUpdater.NoteRecipient = (title, text, pids, image1, image2) => notificationPanel.AddNote(title, text, pids, image1, image2);
|
||||
ModelUpdater.NoteRecipient = (title, text, pids, image1, image2) =>
|
||||
notificationPanel.AddNote(title, text, pids, image1, image2);
|
||||
ModelUpdater.FetchHeadshot = (imagePath) => awsResourceFetcher.GetImage(imagePath);
|
||||
|
||||
commitCommandButton.gameObject.SetActive(false);
|
||||
@@ -209,44 +181,38 @@ namespace eagle
|
||||
|
||||
ModelUpdater.errorPanel = errorPanel;
|
||||
|
||||
MainQueue.Q.EnqueueForNextUpdate(() =>
|
||||
{
|
||||
ModelUpdater.StartListeningForUpdates();
|
||||
});
|
||||
MainQueue.Q.EnqueueForNextUpdate(() => { ModelUpdater.StartListeningForUpdates(); });
|
||||
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.playModeStateChanged += (state) => OnPlayModeStateChanged(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SelectRecommendedCommand(ProvinceId provinceId)
|
||||
{
|
||||
private void SelectRecommendedCommand(ProvinceId provinceId) {
|
||||
OneProvinceAvailableCommands opac;
|
||||
if (Model.AvailableCommandsByProvince.TryGetValue(provinceId, out opac))
|
||||
{
|
||||
if (Model.AvailableCommandsByProvince.TryGetValue(provinceId, out opac)) {
|
||||
SelectButtonIndex(opac.SuggestedCommandIndex); // probably wrong
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectNextActiveProvince()
|
||||
{
|
||||
public void SelectNextActiveProvince() {
|
||||
mapController.SelectedProvinceId = NextActiveProvinceKeyPair.Key;
|
||||
}
|
||||
|
||||
public void SelectButtonIndex(int buttonIndex)
|
||||
{
|
||||
var selector = Model.AvailableCommandsForProvince(SelectedProvince.Value)
|
||||
public void SelectButtonIndex(int buttonIndex) {
|
||||
var selector =
|
||||
Model.AvailableCommandsForProvince(SelectedProvince.Value)
|
||||
.SelectMany(cmd => commandPanelController.AppropriateSelectors(cmd))
|
||||
.ElementAt(buttonIndex);
|
||||
|
||||
var newType = selector.CommandType;
|
||||
var cmd = Model.AvailableCommandsForProvince(SelectedProvince.Value).Find(c => c.SealedValueCase == newType);
|
||||
var commandIndex = Model.AvailableCommandsForProvince(SelectedProvince.Value).IndexOf(cmd);
|
||||
var cmd = Model.AvailableCommandsForProvince(SelectedProvince.Value)
|
||||
.Find(c => c.SealedValueCase == newType);
|
||||
var commandIndex =
|
||||
Model.AvailableCommandsForProvince(SelectedProvince.Value).IndexOf(cmd);
|
||||
|
||||
commandPanelController.SetAvailableCommandAndSelector(cmd, selector);
|
||||
mapController.ProvincesWithCommands = new List<ProvinceId>();
|
||||
@@ -254,38 +220,32 @@ namespace eagle
|
||||
heroesAndBattalionsPanelController.UpdateTables();
|
||||
}
|
||||
|
||||
private void UpdateButtons()
|
||||
{
|
||||
if (SelectedProvince.HasValue)
|
||||
{
|
||||
commandButtonController.SetButtonContents(Model
|
||||
.AvailableCommandsForProvince(SelectedProvince.Value)
|
||||
.SelectMany(cmd => commandPanelController.ButtonContentsForCommand(cmd))
|
||||
private void UpdateButtons() {
|
||||
if (SelectedProvince.HasValue) {
|
||||
commandButtonController.SetButtonContents(
|
||||
Model.AvailableCommandsForProvince(SelectedProvince.Value)
|
||||
.SelectMany(
|
||||
cmd => commandPanelController.ButtonContentsForCommand(cmd))
|
||||
.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
commandButtonController.ClearButtonContents();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNextActiveProvinceButton()
|
||||
{
|
||||
nextActiveProvinceButton.gameObject.SetActive(commandPanelController.Selector == null && Model != null && Model.AvailableCommandsByProvince.Count > 0);
|
||||
private void SetNextActiveProvinceButton() {
|
||||
nextActiveProvinceButton.gameObject.SetActive(
|
||||
commandPanelController.Selector == null && Model != null &&
|
||||
Model.AvailableCommandsByProvince.Count > 0);
|
||||
}
|
||||
|
||||
public void ProvinceWasSelected(ProvinceId? pid)
|
||||
{
|
||||
if (pid.HasValue)
|
||||
{
|
||||
public void ProvinceWasSelected(ProvinceId? pid) {
|
||||
if (pid.HasValue) {
|
||||
SelectRecommendedCommand(pid.Value);
|
||||
var currentProvince = Model.Provinces[pid.Value];
|
||||
provinceInfoPanelController.Province = currentProvince;
|
||||
focusInfoPanelController.CurrentProvince = currentProvince;
|
||||
heroesAndBattalionsPanelController.CurrentProvince = currentProvince;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
provinceInfoPanelController.Province = null;
|
||||
focusInfoPanelController.CurrentProvince = null;
|
||||
heroesAndBattalionsPanelController.CurrentProvince = null;
|
||||
@@ -296,33 +256,28 @@ namespace eagle
|
||||
dominionPanelController.ForceUpdate();
|
||||
}
|
||||
|
||||
private void PrefetchHeadshotForHeroes(List<HeroView> heroViews)
|
||||
{
|
||||
private void PrefetchHeadshotForHeroes(List<HeroView> heroViews) {
|
||||
awsResourceFetcher.Prefetch(heroViews.Select(h => h.ImagePath));
|
||||
}
|
||||
|
||||
private void PrefetchHeadshots(GameModel model)
|
||||
{
|
||||
var heroList = model.ActiveFactions.Values.Select(faction => model.Heroes[faction.FactionHeadId]).ToList();
|
||||
private void PrefetchHeadshots(GameModel model) {
|
||||
var heroList = model.ActiveFactions.Values
|
||||
.Select(faction => model.Heroes[faction.FactionHeadId])
|
||||
.ToList();
|
||||
|
||||
foreach (ProvinceView province in model.Provinces.Values)
|
||||
{
|
||||
if (province.FullInfo is FullProvinceInfo fpi)
|
||||
{
|
||||
foreach (ProvinceView province in model.Provinces.Values) {
|
||||
if (province.FullInfo is FullProvinceInfo fpi) {
|
||||
heroList.AddRange(fpi.RulingFactionHeroIds.Select(hid => model.Heroes[hid]));
|
||||
heroList.AddRange(fpi.UnaffiliatedHeroes.Select(uh => uh.HeroId).Select(hid => model.Heroes[hid]));
|
||||
heroList.AddRange(fpi.UnaffiliatedHeroes.Select(uh => uh.HeroId)
|
||||
.Select(hid => model.Heroes[hid]));
|
||||
}
|
||||
}
|
||||
|
||||
PrefetchHeadshotForHeroes(heroList);
|
||||
}
|
||||
|
||||
void SwapModel()
|
||||
{
|
||||
if (newModel == Model)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void SwapModel() {
|
||||
if (newModel == Model) { return; }
|
||||
|
||||
PrefetchHeadshots(newModel);
|
||||
|
||||
@@ -332,74 +287,61 @@ namespace eagle
|
||||
commandPanelController.Model = newModel;
|
||||
dominionPanelController.Model = newModel;
|
||||
|
||||
if (newModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (newModel == null) { return; }
|
||||
var oldModel = Model;
|
||||
Model = newModel;
|
||||
|
||||
mapController.Model = Model;
|
||||
if ((oldModel == null || oldModel.CommandToken != newModel.CommandToken) && Model.AvailableCommandsByProvince.Count > 0)
|
||||
{
|
||||
if (oldModel != null && oldModel.AvailableCommandsByProvince.Count > 0)
|
||||
{
|
||||
string str = "We got replacement commands, but we already had commands. " + oldModel.CommandToken + " " + newModel.CommandToken;
|
||||
if ((oldModel == null || oldModel.CommandToken != newModel.CommandToken) &&
|
||||
Model.AvailableCommandsByProvince.Count > 0) {
|
||||
if (oldModel != null && oldModel.AvailableCommandsByProvince.Count > 0) {
|
||||
string str = "We got replacement commands, but we already had commands. " +
|
||||
oldModel.CommandToken + " " + newModel.CommandToken;
|
||||
|
||||
var oldProvinces = oldModel.AvailableCommandsByProvince.Keys.ToHashSet();
|
||||
var newProvinces = newModel.AvailableCommandsByProvince.Keys.ToHashSet();
|
||||
|
||||
if (oldProvinces != newProvinces)
|
||||
{
|
||||
if (oldProvinces != newProvinces) {
|
||||
var oldNotNew = oldProvinces.Except(newProvinces);
|
||||
if (oldNotNew.Any())
|
||||
{
|
||||
if (oldNotNew.Any()) {
|
||||
str += $"\nWe used to have commands for province {oldNotNew} but now we don't";
|
||||
}
|
||||
|
||||
var newNotOld = newProvinces.Except(oldProvinces);
|
||||
if (newNotOld.Any())
|
||||
{
|
||||
if (newNotOld.Any()) {
|
||||
str += $"\nWe now have commands for provinces {newNotOld} where we didn't before";
|
||||
}
|
||||
}
|
||||
foreach (var kv in oldModel.AvailableCommandsByProvince)
|
||||
{
|
||||
if (newModel.AvailableCommandsByProvince.ContainsKey(kv.Key))
|
||||
{
|
||||
|
||||
foreach (var kv in oldModel.AvailableCommandsByProvince) {
|
||||
if (newModel.AvailableCommandsByProvince.ContainsKey(kv.Key)) {
|
||||
var oldCommands = kv.Value;
|
||||
var newCommands = newModel.AvailableCommandsByProvince[kv.Key];
|
||||
if (oldCommands.Commands.Count != newCommands.Commands.Count)
|
||||
{
|
||||
if (oldCommands.Commands.Count != newCommands.Commands.Count) {
|
||||
str += $"\nWe had {oldCommands.Commands.Count} but now we have {newCommands.Commands.Count}";
|
||||
}
|
||||
|
||||
foreach (var cmd in oldCommands.Commands)
|
||||
{
|
||||
if (!newCommands.Commands.Contains(cmd))
|
||||
{
|
||||
foreach (var cmd in oldCommands.Commands) {
|
||||
if (!newCommands.Commands.Contains(cmd)) {
|
||||
str += $"\nWe had {cmd} but now we don't";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var cmd in newCommands.Commands)
|
||||
{
|
||||
if (!oldCommands.Commands.Contains(cmd))
|
||||
{
|
||||
foreach (var cmd in newCommands.Commands) {
|
||||
if (!oldCommands.Commands.Contains(cmd)) {
|
||||
str += $"\nWe have {cmd}, we didn't before";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
throw new InvalidOperationException(str);
|
||||
}
|
||||
switch (Model.AvailableCommandsByProvince.First().Value.Commands.First().SealedValueCase)
|
||||
{
|
||||
switch (Model.AvailableCommandsByProvince.First()
|
||||
.Value.Commands.First()
|
||||
.SealedValueCase) {
|
||||
case AvailableCommand.SealedValueOneofCase.ResolveTreatyOfferCommand:
|
||||
resolveTreatyCommandSelector.Model = Model;
|
||||
resolveTreatyCommandSelector.AvailableCommand = Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
resolveTreatyCommandSelector.AvailableCommand =
|
||||
Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
mapController.SelectedProvinceId = null;
|
||||
@@ -407,7 +349,8 @@ namespace eagle
|
||||
|
||||
case AvailableCommand.SealedValueOneofCase.ResolveInvitationCommand:
|
||||
resolveInvitationCommandSelector.Model = Model;
|
||||
resolveInvitationCommandSelector.AvailableCommand = Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
resolveInvitationCommandSelector.AvailableCommand =
|
||||
Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
mapController.SelectedProvinceId = null;
|
||||
@@ -415,7 +358,8 @@ namespace eagle
|
||||
|
||||
case AvailableCommand.SealedValueOneofCase.ResolveRansomOfferCommand:
|
||||
resolveRansomOfferCommandSelector.Model = Model;
|
||||
resolveRansomOfferCommandSelector.AvailableCommand = Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
resolveRansomOfferCommandSelector.AvailableCommand =
|
||||
Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
mapController.SelectedProvinceId = null;
|
||||
@@ -423,7 +367,8 @@ namespace eagle
|
||||
|
||||
case AvailableCommand.SealedValueOneofCase.PleaseRecruitMeCommand:
|
||||
pleaseRecruitMeCommandSelector.Model = Model;
|
||||
pleaseRecruitMeCommandSelector.AvailableCommand = Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
pleaseRecruitMeCommandSelector.AvailableCommand =
|
||||
Model.AvailableCommandsByProvince.First().Value.Commands.First();
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
mapController.SelectedProvinceId = null;
|
||||
@@ -437,29 +382,26 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
if (oldModel != null &&
|
||||
oldModel.AvailableCommandsByProvince.Any() &&
|
||||
if (oldModel != null && oldModel.AvailableCommandsByProvince.Any() &&
|
||||
newModel.AvailableCommandsByProvince.Any() &&
|
||||
oldModel.AvailableCommandsByProvince == newModel.AvailableCommandsByProvince)
|
||||
{
|
||||
// We got the same set of commands. This shouldn't happen; let's throw an exception indicating the command we got.
|
||||
//string str = "We got exactly the same set of commands! This could cause a bad reset. Last ActionResultView was ";
|
||||
//str += newModel.lastActionResultView.ToString();
|
||||
oldModel.AvailableCommandsByProvince == newModel.AvailableCommandsByProvince) {
|
||||
// We got the same set of commands. This shouldn't happen; let's throw an exception
|
||||
// indicating the command we got.
|
||||
// string str = "We got exactly the same set of commands! This could cause a bad
|
||||
// reset. Last ActionResultView was "; str +=
|
||||
// newModel.lastActionResultView.ToString();
|
||||
|
||||
// throw new InvalidOperationException(str);
|
||||
}
|
||||
|
||||
|
||||
focusInfoPanelController.UpdateTables();
|
||||
heroesAndBattalionsPanelController.UpdateTables();
|
||||
|
||||
Canvas.ForceUpdateCanvases();
|
||||
var date = Model.CurrentDate;
|
||||
if (date != null)
|
||||
{
|
||||
if (date != null) {
|
||||
string factionLabel = "Observer";
|
||||
if (Model.PlayerId.HasValue)
|
||||
{
|
||||
if (Model.PlayerId.HasValue) {
|
||||
var faction = Model.MaybeDestroyedFaction(Model.PlayerId.Value);
|
||||
factionLabel = $"{faction.Name} ({faction.Prestige})";
|
||||
}
|
||||
@@ -467,58 +409,43 @@ namespace eagle
|
||||
}
|
||||
|
||||
goToBattleButton.gameObject.SetActive(Model.ShardokGameModels.Count > 0);
|
||||
foreach (var shardokGameModel in Model.ShardokGameModels.Values)
|
||||
{
|
||||
if (shardokGameModel.PlayerId != -1)
|
||||
{
|
||||
foreach (var shardokGameModel in Model.ShardokGameModels.Values) {
|
||||
if (shardokGameModel.PlayerId != -1) {
|
||||
goToBattleButtonText.text = "Battle!";
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
goToBattleButtonText.text = "Observe Battle";
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < Model.ShardokBattles.Count; i++)
|
||||
{
|
||||
|
||||
}
|
||||
for (int i = 0; i < Model.ShardokBattles.Count; i++) {}
|
||||
|
||||
newModel = null;
|
||||
SetNextActiveProvinceButton();
|
||||
|
||||
if (Model.AvailableCommandsByProvince.Count > 0 && Model.AvailableCommandsByProvince.ContainsKey(0))
|
||||
{
|
||||
if (Model.AvailableCommandsByProvince.Count > 0 &&
|
||||
Model.AvailableCommandsByProvince.ContainsKey(0)) {
|
||||
mapController.ProvincesWithCommands = new List<ProvinceId>();
|
||||
}
|
||||
else
|
||||
{
|
||||
mapController.ProvincesWithCommands = Model.AvailableCommandsByProvince.Keys.ToList();
|
||||
} else {
|
||||
mapController.ProvincesWithCommands =
|
||||
Model.AvailableCommandsByProvince.Keys.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
void ModelUpdated(GameModel nm)
|
||||
{
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
newModel = nm;
|
||||
void ModelUpdated(GameModel nm) {
|
||||
MainQueue.Q.Enqueue(() => { newModel = nm; });
|
||||
}
|
||||
|
||||
private void PostCommittedCommand(ProvinceId provinceId, SelectedCommand selectedCommand) {
|
||||
ModelUpdater.PostCommand(provinceId: provinceId, command: selectedCommand)
|
||||
.ContinueWith(response => {
|
||||
if (response.IsFaulted) { errorPanel.Add(response.Exception); }
|
||||
});
|
||||
}
|
||||
|
||||
private void PostCommittedCommand(ProvinceId provinceId, SelectedCommand selectedCommand)
|
||||
{
|
||||
ModelUpdater.PostCommand(provinceId: provinceId, command: selectedCommand).ContinueWith(response =>
|
||||
{
|
||||
if (response.IsFaulted)
|
||||
{
|
||||
errorPanel.Add(response.Exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DoCommitCommand()
|
||||
{
|
||||
PostCommittedCommand(provinceId: mapController.SelectedProvinceId.GetValueOrDefault(), commandPanelController.SelectedCommand);
|
||||
private void DoCommitCommand() {
|
||||
PostCommittedCommand(
|
||||
provinceId: mapController.SelectedProvinceId.GetValueOrDefault(),
|
||||
commandPanelController.SelectedCommand);
|
||||
commitCommandButton.gameObject.SetActive(false);
|
||||
commandPanelController.SetAvailableCommandAndSelector(null, null);
|
||||
mapController.TargetedProvinces = new List<ProvinceId>();
|
||||
@@ -527,17 +454,16 @@ namespace eagle
|
||||
heroesAndBattalionsPanelController.UpdateTables();
|
||||
}
|
||||
|
||||
public void CommitCommandButtonClicked()
|
||||
{
|
||||
public void CommitCommandButtonClicked() {
|
||||
commandWarningPanelController.ClearWarning();
|
||||
DoCommitCommand();
|
||||
}
|
||||
|
||||
public void GoToBattle()
|
||||
{
|
||||
public void GoToBattle() {
|
||||
var myBattles = Model.ShardokGameModels.Values.Where(sgm => sgm.PlayerId != -1);
|
||||
|
||||
var selectedModel = (myBattles.Count() > 0) ? myBattles.First(b => b.PlayerId != -1) : Model.ShardokGameModels.Values.First();
|
||||
var selectedModel = (myBattles.Count() > 0) ? myBattles.First(b => b.PlayerId != -1)
|
||||
: Model.ShardokGameModels.Values.First();
|
||||
|
||||
goToBattleButton.gameObject.SetActive(false);
|
||||
|
||||
@@ -548,13 +474,11 @@ namespace eagle
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void DominionViewToggleClicked(bool value)
|
||||
{
|
||||
public void DominionViewToggleClicked(bool value) {
|
||||
dominionPanelController.gameObject.SetActive(value);
|
||||
}
|
||||
|
||||
void HandleQuit()
|
||||
{
|
||||
void HandleQuit() {
|
||||
#if UNITY_EDITOR
|
||||
// UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
@@ -563,8 +487,7 @@ namespace eagle
|
||||
#endif
|
||||
}
|
||||
|
||||
public void GameIdButtonClicked()
|
||||
{
|
||||
public void GameIdButtonClicked() {
|
||||
var textField = gameIdButton.GetComponentInChildren<Text>();
|
||||
textField.text = textField.text == "" ? ModelUpdater.GameId.ToString("X") : "";
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+88
-140
@@ -8,20 +8,15 @@ using ProvinceId = System.Int32;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class FocusInfoPanelController : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class FocusInfoPanelController : MonoBehaviour {
|
||||
public GameObject panel;
|
||||
|
||||
private ProvinceView _currentProvince;
|
||||
public ProvinceView CurrentProvince
|
||||
{
|
||||
public ProvinceView CurrentProvince {
|
||||
get => _currentProvince;
|
||||
set
|
||||
{
|
||||
if (_currentProvince != value)
|
||||
{
|
||||
set {
|
||||
if (_currentProvince != value) {
|
||||
_currentProvince = value;
|
||||
UpdateTables();
|
||||
}
|
||||
@@ -29,10 +24,9 @@ namespace eagle
|
||||
}
|
||||
|
||||
private GameModel _model;
|
||||
public GameModel Model
|
||||
{
|
||||
private get => _model; set
|
||||
{
|
||||
public GameModel Model { private
|
||||
get => _model;
|
||||
set {
|
||||
_model = value;
|
||||
UpdateTables();
|
||||
panel.SetActive(value != null);
|
||||
@@ -47,12 +41,11 @@ namespace eagle
|
||||
public CommandPanelController commandPanelController;
|
||||
public MapController mapController;
|
||||
|
||||
private CommandSelector CommandSelector => commandPanelController == null ? null : commandPanelController.Selector;
|
||||
private CommandSelector CommandSelector =>
|
||||
commandPanelController == null ? null : commandPanelController.Selector;
|
||||
|
||||
public void UpdateTables()
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
public void UpdateTables() {
|
||||
if (Model == null) {
|
||||
panel.SetActive(false);
|
||||
return;
|
||||
}
|
||||
@@ -62,76 +55,60 @@ namespace eagle
|
||||
setUpFactions();
|
||||
}
|
||||
|
||||
private void SetUnaffiliatedHeroRowSelections(UnaffiliatedHeroRowController row, UnaffiliatedHeroBasics uh)
|
||||
{
|
||||
if (CommandSelector == null)
|
||||
{
|
||||
private void SetUnaffiliatedHeroRowSelections(
|
||||
UnaffiliatedHeroRowController row,
|
||||
UnaffiliatedHeroBasics uh) {
|
||||
if (CommandSelector == null) {
|
||||
row.Selected = false;
|
||||
row.Selectable = false;
|
||||
row.RightSelectable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.Selected = commandPanelController.Selector.TargetedHeroIds.Contains(uh.HeroId);
|
||||
row.Selectable = commandPanelController.Selector.HeroIsTargetable(uh.HeroId);
|
||||
row.RightSelectable = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUnaffiliatedHeroSelections()
|
||||
{
|
||||
UnaffiliatedHeroes.Each((uh, i) =>
|
||||
SetUnaffiliatedHeroRowSelections(unaffiliatedHeroesTable.ComponentAt<UnaffiliatedHeroRowController>(i), uh)
|
||||
);
|
||||
public void UpdateUnaffiliatedHeroSelections() {
|
||||
UnaffiliatedHeroes.Each(
|
||||
(uh, i) => SetUnaffiliatedHeroRowSelections(
|
||||
unaffiliatedHeroesTable.ComponentAt<UnaffiliatedHeroRowController>(i),
|
||||
uh));
|
||||
}
|
||||
|
||||
public void UnaffiliatedHeroRowClicked(int index)
|
||||
{
|
||||
public void UnaffiliatedHeroRowClicked(int index) {
|
||||
var heroId = UnaffiliatedHeroes.ElementAt(index).HeroId;
|
||||
if (CommandSelector != null)
|
||||
{
|
||||
CommandSelector.AddTargetedHero(heroId);
|
||||
}
|
||||
if (CommandSelector != null) { CommandSelector.AddTargetedHero(heroId); }
|
||||
UpdateUnaffiliatedHeroSelections();
|
||||
}
|
||||
|
||||
private void setUpUnaffiliatedHeroesTable()
|
||||
{
|
||||
private void setUpUnaffiliatedHeroesTable() {
|
||||
unaffiliatedHeroesTable.RowCount = UnaffiliatedHeroCount;
|
||||
|
||||
UnaffiliatedHeroes.Each((uh, i) =>
|
||||
{
|
||||
UnaffiliatedHeroes.Each((uh, i) => {
|
||||
var newRow = unaffiliatedHeroesTable.ComponentAt<UnaffiliatedHeroRowController>(i);
|
||||
newRow.SetUnaffiliatedHero(uh, Model);
|
||||
SetUnaffiliatedHeroRowSelections(newRow, uh);
|
||||
});
|
||||
}
|
||||
|
||||
private void setUpIncomingArmiesTable()
|
||||
{
|
||||
private void setUpIncomingArmiesTable() {
|
||||
movingArmiesTable.RowCount = MovingArmiesCount;
|
||||
|
||||
MovingArmies.Each((army, i) =>
|
||||
{
|
||||
MovingArmies.Each((army, i) => {
|
||||
var newRow = movingArmiesTable.ComponentAt<MovingArmyTableRow>(i);
|
||||
if (army.FactionId == Model.PlayerId)
|
||||
{
|
||||
if (army.FactionId == Model.PlayerId) {
|
||||
newRow.Faction = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
newRow.Faction = Model.FactionName(army.FactionId);
|
||||
}
|
||||
newRow.HeroCount = army.HeroCount;
|
||||
newRow.TroopCount = army.TroopCount;
|
||||
newRow.Origin = Model.Provinces[army.OriginProvinceId].Name;
|
||||
newRow.Destination = Model.Provinces[army.DestinationProvinceId].Name;
|
||||
if (CurrentProvince != null && army.DestinationProvinceId == CurrentProvince.Id)
|
||||
{
|
||||
if (CurrentProvince != null && army.DestinationProvinceId == CurrentProvince.Id) {
|
||||
newRow.DestinationColor = Color.blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
newRow.DestinationColor = Color.black;
|
||||
}
|
||||
|
||||
@@ -143,184 +120,155 @@ namespace eagle
|
||||
});
|
||||
}
|
||||
|
||||
private int provinceCount(FactionView faction)
|
||||
{
|
||||
private int provinceCount(FactionView faction) {
|
||||
return Model.Provinces.Values.Count(pv => pv.RulingFactionId == faction.Id);
|
||||
}
|
||||
|
||||
private Treaty existingTreaty(FactionView faction)
|
||||
{
|
||||
if (Model.PlayerId is FactionId myFid)
|
||||
{
|
||||
return Model.MaybeDestroyedFaction(myFid).Treaties.FirstOrDefault(t => t.TargetFactionId == faction.Id);
|
||||
}
|
||||
else return null;
|
||||
private Treaty existingTreaty(FactionView faction) {
|
||||
if (Model.PlayerId is FactionId myFid) {
|
||||
return Model.MaybeDestroyedFaction(myFid).Treaties.FirstOrDefault(
|
||||
t => t.TargetFactionId == faction.Id);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SetUpFactionRow(FactionView faction, FactionTableRow row)
|
||||
{
|
||||
private void SetUpFactionRow(FactionView faction, FactionTableRow row) {
|
||||
row.Faction = faction.Name;
|
||||
row.FactionId = faction.Id;
|
||||
row.FactionColor = PlayerColors.LightPlayerColor(faction.Id);
|
||||
row.ProvinceCount = Model.Provinces.Values.Count(pv => pv.RulingFactionId == faction.Id);
|
||||
row.ProvinceCount =
|
||||
Model.Provinces.Values.Count(pv => pv.RulingFactionId == faction.Id);
|
||||
|
||||
Treaty treaty = existingTreaty(faction);
|
||||
|
||||
if (treaty == null)
|
||||
{
|
||||
if (treaty == null) {
|
||||
row.TreatyStatus = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.TreatyStatus = $"Treaty until {DisplayNames.DateString(treaty.EndDate)}";
|
||||
}
|
||||
|
||||
if (CommandSelector != null)
|
||||
{
|
||||
if (CommandSelector != null) {
|
||||
row.Selectable = CommandSelector.FactionIsTargetable(faction.Id);
|
||||
row.Selected = CommandSelector.TargetedFactionIds.Contains(faction.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpFactions()
|
||||
{
|
||||
private void setUpFactions() {
|
||||
var displayedFactions = DisplayedFactions.ToList();
|
||||
|
||||
leftFactionsTable.RowCount = (displayedFactions.Count + 1) / 2;
|
||||
rightFactionsTable.RowCount = (displayedFactions.Count) / 2;
|
||||
|
||||
for (int i = 0; i < (displayedFactions.Count + 1) / 2; i++)
|
||||
{
|
||||
for (int i = 0; i < (displayedFactions.Count + 1) / 2; i++) {
|
||||
var newLeftRow = leftFactionsTable.ComponentAt<FactionTableRow>(i);
|
||||
SetUpFactionRow(displayedFactions.ElementAt(2 * i), newLeftRow);
|
||||
|
||||
if (2 * i + 1 < displayedFactions.Count)
|
||||
{
|
||||
if (2 * i + 1 < displayedFactions.Count) {
|
||||
var newRightRow = rightFactionsTable.ComponentAt<FactionTableRow>(i);
|
||||
SetUpFactionRow(displayedFactions.ElementAt(2 * i + 1), newRightRow);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void FactionRowHovered(FactionId fid)
|
||||
{
|
||||
public void FactionRowHovered(FactionId fid) {
|
||||
mapController.OverrideTargetedProvinces = Model.ProvincesForFaction(fid).ToList();
|
||||
}
|
||||
|
||||
public void FactionRowUnhovered()
|
||||
{
|
||||
public void FactionRowUnhovered() {
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
}
|
||||
|
||||
public void MovingArmyRowHovered(MovingArmyTableRow row)
|
||||
{
|
||||
for (int i = 0; i < movingArmiesTable.RowCount; i++)
|
||||
{
|
||||
if (movingArmiesTable.ComponentAt<MovingArmyTableRow>(i) == row)
|
||||
{
|
||||
public void MovingArmyRowHovered(MovingArmyTableRow row) {
|
||||
for (int i = 0; i < movingArmiesTable.RowCount; i++) {
|
||||
if (movingArmiesTable.ComponentAt<MovingArmyTableRow>(i) == row) {
|
||||
var army = MovingArmies.ElementAt(i);
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId> { army.OriginProvinceId, army.DestinationProvinceId };
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId> {
|
||||
army.OriginProvinceId,
|
||||
army.DestinationProvinceId
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MovingArmyRowUnhovered()
|
||||
{
|
||||
public void MovingArmyRowUnhovered() {
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
}
|
||||
|
||||
public void ProvinceHovered(ProvinceId? pid)
|
||||
{
|
||||
public void ProvinceHovered(ProvinceId? pid) {
|
||||
// Highlight moving armies table
|
||||
MovingArmies.Each((army, i) =>
|
||||
{
|
||||
MovingArmies.Each((army, i) => {
|
||||
var row = movingArmiesTable.ComponentAt<MovingArmyTableRow>(i);
|
||||
if (army.DestinationProvinceId == pid || army.OriginProvinceId == pid)
|
||||
{
|
||||
if (army.DestinationProvinceId == pid || army.OriginProvinceId == pid) {
|
||||
row.ShadeOn();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.ShadeOff();
|
||||
}
|
||||
});
|
||||
|
||||
// Highlight faction table
|
||||
FactionId? fid = null;
|
||||
if (pid is ProvinceId hoverPid)
|
||||
{
|
||||
fid = Model.Provinces[hoverPid].RulingFactionId;
|
||||
}
|
||||
if (pid is ProvinceId hoverPid) { fid = Model.Provinces[hoverPid].RulingFactionId; }
|
||||
|
||||
for (int i = 0; i < leftFactionsTable.RowCount; i++)
|
||||
{
|
||||
for (int i = 0; i < leftFactionsTable.RowCount; i++) {
|
||||
leftFactionsTable.ComponentAt<FactionTableRow>(i).ShadeOff();
|
||||
}
|
||||
for (int i = 0; i < rightFactionsTable.RowCount; i++)
|
||||
{
|
||||
for (int i = 0; i < rightFactionsTable.RowCount; i++) {
|
||||
rightFactionsTable.ComponentAt<FactionTableRow>(i).ShadeOff();
|
||||
}
|
||||
if (fid is FactionId factionId)
|
||||
{
|
||||
if (fid is FactionId factionId) {
|
||||
var index = DisplayedFactions.FindIndex(f => f.Id == factionId);
|
||||
if (index != -1)
|
||||
{
|
||||
if (index % 2 == 0)
|
||||
{
|
||||
if (index != -1) {
|
||||
if (index % 2 == 0) {
|
||||
leftFactionsTable.ComponentAt<FactionTableRow>(index / 2).ShadeOn();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rightFactionsTable.ComponentAt<FactionTableRow>(index / 2).ShadeOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FactionLeftRowClicked(int index)
|
||||
{
|
||||
public void FactionLeftRowClicked(int index) {
|
||||
var factionId = DisplayedFactions.ElementAt(2 * index).Id;
|
||||
if (CommandSelector != null && CommandSelector.FactionIsTargetable(factionId))
|
||||
{
|
||||
if (CommandSelector != null && CommandSelector.FactionIsTargetable(factionId)) {
|
||||
CommandSelector.AddTargetedFaction(factionId);
|
||||
}
|
||||
setUpFactions();
|
||||
}
|
||||
|
||||
public void FactionRightRowClicked(int index)
|
||||
{
|
||||
public void FactionRightRowClicked(int index) {
|
||||
var factionId = DisplayedFactions.ElementAt(2 * index + 1).Id;
|
||||
if (CommandSelector != null && CommandSelector.FactionIsTargetable(factionId))
|
||||
{
|
||||
if (CommandSelector != null && CommandSelector.FactionIsTargetable(factionId)) {
|
||||
CommandSelector.AddTargetedFaction(factionId);
|
||||
}
|
||||
setUpFactions();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
panel.SetActive(Model != null);
|
||||
}
|
||||
void Start() { panel.SetActive(Model != null); }
|
||||
|
||||
private bool HasProvinceInfo => (CurrentProvince != null && CurrentProvince.FullInfo != null);
|
||||
private bool HasProvinceInfo =>
|
||||
(CurrentProvince != null && CurrentProvince.FullInfo != null);
|
||||
|
||||
private int UnaffiliatedHeroCount => HasProvinceInfo ? CurrentProvince.FullInfo.UnaffiliatedHeroes.Count : 0;
|
||||
private IEnumerable<UnaffiliatedHeroBasics> UnaffiliatedHeroes => HasProvinceInfo
|
||||
? CurrentProvince.FullInfo.UnaffiliatedHeroes.OrderByDescending(uh => Model.Heroes[uh.HeroId].SortKey).ToList()
|
||||
private int UnaffiliatedHeroCount =>
|
||||
HasProvinceInfo ? CurrentProvince.FullInfo.UnaffiliatedHeroes.Count : 0;
|
||||
private IEnumerable<UnaffiliatedHeroBasics> UnaffiliatedHeroes =>
|
||||
HasProvinceInfo ? CurrentProvince.FullInfo.UnaffiliatedHeroes
|
||||
.OrderByDescending(uh => Model.Heroes[uh.HeroId].SortKey)
|
||||
.ToList()
|
||||
: new List<UnaffiliatedHeroBasics>();
|
||||
|
||||
private int MovingArmiesCount => MovingArmies.Count();
|
||||
public IEnumerable<IncomingArmyView> MovingArmies => Model.Provinces.Values
|
||||
.SelectMany(p => p.KnownIncomingArmies)
|
||||
public IEnumerable<IncomingArmyView> MovingArmies =>
|
||||
Model.Provinces.Values.SelectMany(p => p.KnownIncomingArmies)
|
||||
.OrderBy(a => a.FactionId == Model.PlayerId)
|
||||
.ThenBy(a => CurrentProvince != null && a.DestinationProvinceId != CurrentProvince.Id)
|
||||
.ThenBy(a => CurrentProvince != null &&
|
||||
a.DestinationProvinceId != CurrentProvince.Id)
|
||||
.ThenByDescending(a => a.HeroCount);
|
||||
|
||||
private int FactionsCount => Model.ActiveFactions.Count;
|
||||
private IEnumerable<FactionView> ActiveFactions => Model.ActiveFactions.Values;
|
||||
private List<FactionView> DisplayedFactions => Model.ActiveFactions.Values
|
||||
.OrderBy(fac => existingTreaty(fac) != null)
|
||||
private List<FactionView> DisplayedFactions =>
|
||||
Model.ActiveFactions.Values.OrderBy(fac => existingTreaty(fac) != null)
|
||||
.ThenBy(fac => existingTreaty(fac)?.EndDate.Year ?? 0)
|
||||
.ThenBy(fac => existingTreaty(fac)?.EndDate.Month ?? 0)
|
||||
.ToList();
|
||||
|
||||
+21
-32
@@ -5,12 +5,10 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using FactionId = System.Int32;
|
||||
|
||||
public class HeroDetailsController : MonoBehaviour
|
||||
{
|
||||
public class HeroDetailsController : MonoBehaviour {
|
||||
public RawImage HeadshotImage;
|
||||
public RawImage ProfessionImage;
|
||||
public TMP_Text HeroNameText;
|
||||
@@ -30,30 +28,29 @@ namespace eagle
|
||||
|
||||
private string professionName;
|
||||
|
||||
public string StatView(int value)
|
||||
{
|
||||
public string StatView(int value) {
|
||||
if (value == 0) return "??";
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public string StatView(double value)
|
||||
{
|
||||
return StatView((int)value);
|
||||
}
|
||||
public string StatView(double value) { return StatView((int)value); }
|
||||
|
||||
private void SetHeroBasics(HeroView value)
|
||||
{
|
||||
if (value.ImagePath is String imagePath && !string.IsNullOrEmpty(imagePath))
|
||||
{
|
||||
HeadshotImage.texture = gameObject.GetComponentInParent<AWSResourceFetcher>().GetImage(value.ImagePath);
|
||||
private void SetHeroBasics(HeroView value) {
|
||||
if (value.ImagePath is String imagePath && !string.IsNullOrEmpty(imagePath)) {
|
||||
HeadshotImage.texture =
|
||||
gameObject.GetComponentInParent<AWSResourceFetcher>().GetImage(
|
||||
value.ImagePath);
|
||||
}
|
||||
ProfessionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(value.Profession);
|
||||
ProfessionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
value.Profession);
|
||||
ProfessionImage.gameObject.SetActive(ProfessionImage.texture != null);
|
||||
|
||||
HeroNameText.text = value.Name;
|
||||
StrengthText.text = StatView(value.Strength);
|
||||
AgilityText.text = StatView(value.Agility);
|
||||
VigorText.text = $"{GUIUtils.ConditionString(value.Vigor)}/{StatView(value.Constitution)}";
|
||||
VigorText.text =
|
||||
$"{GUIUtils.ConditionString(value.Vigor)}/{StatView(value.Constitution)}";
|
||||
CharismaText.text = StatView(value.Charisma);
|
||||
WisdomText.text = StatView(value.Wisdom);
|
||||
|
||||
@@ -63,8 +60,7 @@ namespace eagle
|
||||
professionName = DisplayNames.ProfessionNames[value.Profession];
|
||||
}
|
||||
|
||||
private void SetOrdinaryHero(HeroView value)
|
||||
{
|
||||
private void SetOrdinaryHero(HeroView value) {
|
||||
SetHeroBasics(value);
|
||||
|
||||
vipImageContainer.gameObject.SetActive(false);
|
||||
@@ -72,29 +68,22 @@ namespace eagle
|
||||
factionColorImage.color = Color.clear;
|
||||
}
|
||||
|
||||
private void SetFactionLeader(HeroView value, Color factionColor)
|
||||
{
|
||||
private void SetFactionLeader(HeroView value, Color factionColor) {
|
||||
SetOrdinaryHero(value);
|
||||
vipImageContainer.gameObject.SetActive(true);
|
||||
|
||||
factionColorImage.color = factionColor;
|
||||
}
|
||||
|
||||
public void SetHero(HeroView hero, GameModel model)
|
||||
{
|
||||
if (hero.FactionId is FactionId fid && model.ActiveFactions[fid].Leaders.Contains(hero.Id))
|
||||
{
|
||||
public void SetHero(HeroView hero, GameModel model) {
|
||||
if (hero.FactionId is FactionId fid &&
|
||||
model.ActiveFactions[fid].Leaders.Contains(hero.Id)) {
|
||||
SetFactionLeader(hero, PlayerColors.LightPlayerColor(fid));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetOrdinaryHero(hero);
|
||||
}
|
||||
}
|
||||
|
||||
public void ProfessionImageHover()
|
||||
{
|
||||
tooltip.text = professionName;
|
||||
}
|
||||
public void ProfessionImageHover() { tooltip.text = professionName; }
|
||||
}
|
||||
}
|
||||
+52
-82
@@ -4,20 +4,15 @@ using System.Linq;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using common;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class HeroesAndBattalionsPanelController : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class HeroesAndBattalionsPanelController : MonoBehaviour {
|
||||
public GameObject panel;
|
||||
|
||||
private ProvinceView _currentProvince;
|
||||
public ProvinceView CurrentProvince
|
||||
{
|
||||
public ProvinceView CurrentProvince {
|
||||
get => _currentProvince;
|
||||
set
|
||||
{
|
||||
if (_currentProvince != value)
|
||||
{
|
||||
set {
|
||||
if (_currentProvince != value) {
|
||||
_currentProvince = value;
|
||||
UpdateTables();
|
||||
}
|
||||
@@ -25,10 +20,9 @@ namespace eagle
|
||||
}
|
||||
|
||||
private GameModel _model;
|
||||
public GameModel Model
|
||||
{
|
||||
private get => _model; set
|
||||
{
|
||||
public GameModel Model { private
|
||||
get => _model;
|
||||
set {
|
||||
_model = value;
|
||||
UpdateTables();
|
||||
panel.SetActive(value != null);
|
||||
@@ -41,12 +35,11 @@ namespace eagle
|
||||
|
||||
public CommandPanelController commandPanelController;
|
||||
|
||||
private CommandSelector CommandSelector => commandPanelController == null ? null : commandPanelController.Selector;
|
||||
private CommandSelector CommandSelector =>
|
||||
commandPanelController == null ? null : commandPanelController.Selector;
|
||||
|
||||
public void UpdateTables()
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
public void UpdateTables() {
|
||||
if (Model == null) {
|
||||
panel.SetActive(false);
|
||||
return;
|
||||
}
|
||||
@@ -55,131 +48,108 @@ namespace eagle
|
||||
setUpBattalionsTable();
|
||||
}
|
||||
|
||||
private void SetHeroRowSelections(HeroRowController row, HeroView hero)
|
||||
{
|
||||
if (CommandSelector == null)
|
||||
{
|
||||
private void SetHeroRowSelections(HeroRowController row, HeroView hero) {
|
||||
if (CommandSelector == null) {
|
||||
row.Selected = false;
|
||||
row.Selectable = false;
|
||||
row.RightSelectable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.Selected = CommandSelector.TargetedHeroIds.Contains(hero.Id);
|
||||
row.Selectable = CommandSelector.HeroIsTargetable(hero.Id);
|
||||
row.RightSelectable = CommandSelector.TargetedHeroIds.Contains(hero.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBattalionRowSelections(BattalionRowController row, BattalionView batt)
|
||||
{
|
||||
if (CommandSelector == null)
|
||||
{
|
||||
private void SetBattalionRowSelections(BattalionRowController row, BattalionView batt) {
|
||||
if (CommandSelector == null) {
|
||||
row.Selected = false;
|
||||
row.Selectable = false;
|
||||
row.RightSelectable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row.Selected = CommandSelector.TargetedBattalionIds.Contains(batt.Id);
|
||||
row.Selectable = CommandSelector.BattalionIsTargetable(batt.Id);
|
||||
row.RightSelectable = CommandSelector.TargetedBattalionIds.Contains(batt.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateHeroSelections()
|
||||
{
|
||||
Heroes.Each((hero, i) =>
|
||||
SetHeroRowSelections(heroesTable.ComponentAt<HeroRowController>(i), hero)
|
||||
);
|
||||
public void UpdateHeroSelections() {
|
||||
Heroes.Each(
|
||||
(hero, i) => SetHeroRowSelections(
|
||||
heroesTable.ComponentAt<HeroRowController>(i),
|
||||
hero));
|
||||
}
|
||||
|
||||
public void UpdateBattalionSelections()
|
||||
{
|
||||
Battalions.Each((batt, i) =>
|
||||
SetBattalionRowSelections(battalionsTable.ComponentAt<BattalionRowController>(i), batt)
|
||||
);
|
||||
public void UpdateBattalionSelections() {
|
||||
Battalions.Each(
|
||||
(batt, i) => SetBattalionRowSelections(
|
||||
battalionsTable.ComponentAt<BattalionRowController>(i),
|
||||
batt));
|
||||
}
|
||||
|
||||
public void HeroRowClicked(int index)
|
||||
{
|
||||
public void HeroRowClicked(int index) {
|
||||
var heroId = Heroes.ElementAt(index).Id;
|
||||
if (CommandSelector != null && CommandSelector.HeroIsTargetable(heroId))
|
||||
{
|
||||
if (CommandSelector != null && CommandSelector.HeroIsTargetable(heroId)) {
|
||||
CommandSelector.AddTargetedHero(heroId);
|
||||
}
|
||||
UpdateHeroSelections();
|
||||
}
|
||||
|
||||
public void HeroRowRightClicked(int index)
|
||||
{
|
||||
public void HeroRowRightClicked(int index) {
|
||||
var heroId = Heroes.ElementAt(index).Id;
|
||||
if (CommandSelector != null)
|
||||
{
|
||||
CommandSelector.RemoveTargetedHero(heroId);
|
||||
}
|
||||
if (CommandSelector != null) { CommandSelector.RemoveTargetedHero(heroId); }
|
||||
UpdateHeroSelections();
|
||||
}
|
||||
|
||||
public void BattalionRowClicked(int index)
|
||||
{
|
||||
public void BattalionRowClicked(int index) {
|
||||
var battalionId = Battalions.ElementAt(index).Id;
|
||||
if (CommandSelector != null && CommandSelector.BattalionIsTargetable(battalionId))
|
||||
{
|
||||
if (CommandSelector != null && CommandSelector.BattalionIsTargetable(battalionId)) {
|
||||
CommandSelector.AddTargetedBattalion(battalionId);
|
||||
}
|
||||
UpdateBattalionSelections();
|
||||
}
|
||||
|
||||
public void BattalionRowRightClicked(int index)
|
||||
{
|
||||
public void BattalionRowRightClicked(int index) {
|
||||
var battalionId = Battalions.ElementAt(index).Id;
|
||||
if (CommandSelector != null)
|
||||
{
|
||||
CommandSelector.RemoveTargetedBattalion(battalionId);
|
||||
}
|
||||
if (CommandSelector != null) { CommandSelector.RemoveTargetedBattalion(battalionId); }
|
||||
UpdateBattalionSelections();
|
||||
}
|
||||
|
||||
private void setUpHeroesTable()
|
||||
{
|
||||
private void setUpHeroesTable() {
|
||||
heroesTable.RowCount = HeroCount;
|
||||
|
||||
Heroes.Each((hero, i) =>
|
||||
{
|
||||
Heroes.Each((hero, i) => {
|
||||
var row = heroesTable.ComponentAt<HeroRowController>(i);
|
||||
row.Hero = hero;
|
||||
SetHeroRowSelections(row, hero);
|
||||
});
|
||||
}
|
||||
|
||||
private void setUpBattalionsTable()
|
||||
{
|
||||
private void setUpBattalionsTable() {
|
||||
battalionsTable.RowCount = BattalionCount;
|
||||
|
||||
Battalions.Each((battalion, i) =>
|
||||
{
|
||||
Battalions.Each((battalion, i) => {
|
||||
var newRow = battalionsTable.ComponentAt<BattalionRowController>(i);
|
||||
newRow.Battalion = battalion;
|
||||
SetBattalionRowSelections(newRow, battalion);
|
||||
});
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
panel.SetActive(Model != null);
|
||||
}
|
||||
void Start() { panel.SetActive(Model != null); }
|
||||
|
||||
private bool HasProvinceInfo => (CurrentProvince != null && CurrentProvince.FullInfo != null);
|
||||
private bool HasProvinceInfo =>
|
||||
(CurrentProvince != null && CurrentProvince.FullInfo != null);
|
||||
|
||||
private int HeroCount => HasProvinceInfo ? CurrentProvince.FullInfo.RulingFactionHeroIds.Count : 0;
|
||||
private IEnumerable<HeroView> Heroes => HasProvinceInfo
|
||||
? CurrentProvince.FullInfo.RulingFactionHeroIds.Select(id => Model.Heroes[id])
|
||||
private int HeroCount =>
|
||||
HasProvinceInfo ? CurrentProvince.FullInfo.RulingFactionHeroIds.Count : 0;
|
||||
private IEnumerable<HeroView> Heroes =>
|
||||
HasProvinceInfo ? CurrentProvince.FullInfo.RulingFactionHeroIds.Select(
|
||||
id => Model.Heroes[id])
|
||||
: new List<HeroView>();
|
||||
|
||||
private int BattalionCount => HasProvinceInfo ? CurrentProvince.FullInfo.Battalions.Count : 0;
|
||||
private IEnumerable<BattalionView> Battalions => HasProvinceInfo
|
||||
? ProvinceUtils.OrderedBattalions(CurrentProvince)
|
||||
private int BattalionCount =>
|
||||
HasProvinceInfo ? CurrentProvince.FullInfo.Battalions.Count : 0;
|
||||
private IEnumerable<BattalionView> Battalions =>
|
||||
HasProvinceInfo ? ProvinceUtils.OrderedBattalions(CurrentProvince)
|
||||
: new List<BattalionView>();
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ using UnityEngine.UI;
|
||||
using ProvinceId = System.Int32;
|
||||
using FactionId = System.Int32;
|
||||
|
||||
public class MapController : MonoBehaviour
|
||||
{
|
||||
public class MapController : MonoBehaviour {
|
||||
public eagle.EagleGameController eagleGameController;
|
||||
|
||||
public RawImage mapBWImage;
|
||||
@@ -21,16 +20,13 @@ public class MapController : MonoBehaviour
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
private void SetDefaultProvinceColor(ProvinceId provinceId)
|
||||
{
|
||||
private void SetDefaultProvinceColor(ProvinceId provinceId) {
|
||||
SetProvinceColor(provinceId, colorForProvince(Model.Provinces[provinceId]));
|
||||
}
|
||||
|
||||
private void SetProvinceColor(ProvinceId provinceId, Color color)
|
||||
{
|
||||
private void SetProvinceColor(ProvinceId provinceId, Color color) {
|
||||
var image = ImageForProvince(provinceId);
|
||||
if (image.texture == null)
|
||||
{
|
||||
if (image.texture == null) {
|
||||
Texture2D texture = new Texture2D(1, 1);
|
||||
texture.wrapMode = TextureWrapMode.Repeat;
|
||||
image.texture = texture;
|
||||
@@ -42,13 +38,10 @@ public class MapController : MonoBehaviour
|
||||
}
|
||||
|
||||
private ProvinceId? _selectedProvinceId;
|
||||
public ProvinceId? SelectedProvinceId
|
||||
{
|
||||
public ProvinceId? SelectedProvinceId {
|
||||
get => _selectedProvinceId;
|
||||
set
|
||||
{
|
||||
if (_selectedProvinceId is ProvinceId provinceId)
|
||||
{
|
||||
set {
|
||||
if (_selectedProvinceId is ProvinceId provinceId) {
|
||||
SetDefaultProvinceColor(provinceId);
|
||||
}
|
||||
_selectedProvinceId = value;
|
||||
@@ -57,21 +50,12 @@ public class MapController : MonoBehaviour
|
||||
}
|
||||
|
||||
private List<ProvinceId> _targetedProvinces = new List<ProvinceId>();
|
||||
public List<ProvinceId> TargetedProvinces
|
||||
{
|
||||
public List<ProvinceId> TargetedProvinces {
|
||||
get => _targetedProvinces;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = new List<ProvinceId>();
|
||||
}
|
||||
if (!Enumerable.SequenceEqual(_targetedProvinces, value))
|
||||
{
|
||||
foreach (ProvinceId pid in _targetedProvinces)
|
||||
{
|
||||
SetDefaultProvinceColor(pid);
|
||||
}
|
||||
set {
|
||||
if (value == null) { value = new List<ProvinceId>(); }
|
||||
if (!Enumerable.SequenceEqual(_targetedProvinces, value)) {
|
||||
foreach (ProvinceId pid in _targetedProvinces) { SetDefaultProvinceColor(pid); }
|
||||
|
||||
_targetedProvinces = new List<ProvinceId>(value);
|
||||
}
|
||||
@@ -79,19 +63,12 @@ public class MapController : MonoBehaviour
|
||||
}
|
||||
|
||||
private List<ProvinceId> _overrideTargetedProvinces = new List<ProvinceId>();
|
||||
public IList<ProvinceId> OverrideTargetedProvinces
|
||||
{
|
||||
public IList<ProvinceId> OverrideTargetedProvinces {
|
||||
get => _overrideTargetedProvinces;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = new List<ProvinceId>();
|
||||
}
|
||||
if (!Enumerable.SequenceEqual(_overrideTargetedProvinces, value))
|
||||
{
|
||||
foreach (ProvinceId pid in _overrideTargetedProvinces)
|
||||
{
|
||||
set {
|
||||
if (value == null) { value = new List<ProvinceId>(); }
|
||||
if (!Enumerable.SequenceEqual(_overrideTargetedProvinces, value)) {
|
||||
foreach (ProvinceId pid in _overrideTargetedProvinces) {
|
||||
SetDefaultProvinceColor(pid);
|
||||
}
|
||||
|
||||
@@ -103,37 +80,25 @@ public class MapController : MonoBehaviour
|
||||
public Action<List<ProvinceId>> TargetedProvincesChangedCallback;
|
||||
public Action<ProvinceId?> HoveredProvinceChangedCallback;
|
||||
private List<ProvinceId> _provincesWithCommands = new List<ProvinceId>();
|
||||
public List<ProvinceId> ProvincesWithCommands
|
||||
{
|
||||
public List<ProvinceId> ProvincesWithCommands {
|
||||
get => _provincesWithCommands;
|
||||
set
|
||||
{
|
||||
if (!value.SequenceEqual(_provincesWithCommands))
|
||||
{
|
||||
foreach (var pid in _provincesWithCommands)
|
||||
{
|
||||
SetDefaultProvinceColor(pid);
|
||||
}
|
||||
set {
|
||||
if (!value.SequenceEqual(_provincesWithCommands)) {
|
||||
foreach (var pid in _provincesWithCommands) { SetDefaultProvinceColor(pid); }
|
||||
_provincesWithCommands = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameModel _model;
|
||||
public GameModel Model
|
||||
{
|
||||
public GameModel Model {
|
||||
get => _model;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_model = value;
|
||||
|
||||
foreach (var kv in _model.Provinces)
|
||||
{
|
||||
SetDefaultProvinceColor(kv.Value.Id);
|
||||
}
|
||||
foreach (var kv in _model.Provinces) { SetDefaultProvinceColor(kv.Value.Id); }
|
||||
|
||||
foreach (var province in _model.Provinces.Values)
|
||||
{
|
||||
foreach (var province in _model.Provinces.Values) {
|
||||
SetDefaultProvinceColor(province.Id);
|
||||
}
|
||||
|
||||
@@ -155,19 +120,17 @@ public class MapController : MonoBehaviour
|
||||
private byte[] mapIdBytes;
|
||||
ProvinceId? previouslyHoveredProvinceId;
|
||||
|
||||
private Color colorForProvince(ProvinceView province)
|
||||
{
|
||||
private Color colorForProvince(ProvinceView province) {
|
||||
var color = PlayerColors.LightPlayerColor(province.RulingFactionId.GetValueOrDefault(0));
|
||||
if (province.RulingFactionId.HasValue && province.FullInfo != null && province.FullInfo.Support != null && province.FullInfo.Support.Stat < 40)
|
||||
{
|
||||
if (province.RulingFactionId.HasValue && province.FullInfo != null &&
|
||||
province.FullInfo.Support != null && province.FullInfo.Support.Stat < 40) {
|
||||
color = PlayerColors.MutedPlayerColor(province.RulingFactionId.GetValueOrDefault(0));
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
mapIdBytes = rawGray.bytes;
|
||||
imageWidth = mapBWImage.texture.width;
|
||||
imageHeight = mapBWImage.texture.height;
|
||||
@@ -175,134 +138,93 @@ public class MapController : MonoBehaviour
|
||||
previouslyHoveredProvinceId = null;
|
||||
}
|
||||
|
||||
int? ProvinceFromPoint(Vector2 point)
|
||||
{
|
||||
int? ProvinceFromPoint(Vector2 point) {
|
||||
var mousePosition = new Vector2(point.x, Screen.height - point.y);
|
||||
var mapRect = gameObject.GetComponentInParent<PanelPositions>().MapRect;
|
||||
|
||||
var relativeX = (int)((mousePosition.x - mapRect.x) * imageWidth / mapRect.width);
|
||||
var relativeY = (int)(imageHeight - (mousePosition.y - mapRect.y) * imageHeight / mapRect.height);
|
||||
var relativeY =
|
||||
(int)(imageHeight - (mousePosition.y - mapRect.y) * imageHeight / mapRect.height);
|
||||
|
||||
if (relativeX < 0 || relativeX >= imageWidth || relativeY < 0 || relativeY >= imageHeight)
|
||||
{
|
||||
if (relativeX < 0 || relativeX >= imageWidth || relativeY < 0 || relativeY >= imageHeight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var provinceId = mapIdBytes[relativeY * imageWidth + relativeX];
|
||||
if (provinceId == 0 || provinceId == 0xFF)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (provinceId == 0 || provinceId == 0xFF) { return null; }
|
||||
return provinceId;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Model == null || Model.Provinces == null || Model.Provinces.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void Update() {
|
||||
if (Model == null || Model.Provinces == null || Model.Provinces.Count == 0) { return; }
|
||||
|
||||
var maybeHoveredProvinceId = ProvinceFromPoint(Input.mousePosition);
|
||||
if (maybeHoveredProvinceId != previouslyHoveredProvinceId)
|
||||
{
|
||||
if (maybeHoveredProvinceId != previouslyHoveredProvinceId) {
|
||||
previouslyHoveredProvinceId = maybeHoveredProvinceId;
|
||||
HoveredProvinceChangedCallback.Invoke(maybeHoveredProvinceId);
|
||||
if (maybeHoveredProvinceId is ProvinceId hoveredProvinceId)
|
||||
{
|
||||
if (maybeHoveredProvinceId is ProvinceId hoveredProvinceId) {
|
||||
SetUpCenterText(hoveredProvinceId, HOVER_COLOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetUpCenterText(SelectedProvinceId, Color.black);
|
||||
}
|
||||
}
|
||||
|
||||
if (OverrideTargetedProvinces.Any())
|
||||
{
|
||||
if (SelectedProvinceId is ProvinceId sPid)
|
||||
{
|
||||
SetDefaultProvinceColor(sPid);
|
||||
}
|
||||
foreach (ProvinceId tPid in TargetedProvinces)
|
||||
{
|
||||
SetDefaultProvinceColor(tPid);
|
||||
}
|
||||
foreach (var commandProvince in ProvincesWithCommands)
|
||||
{
|
||||
if (OverrideTargetedProvinces.Any()) {
|
||||
if (SelectedProvinceId is ProvinceId sPid) { SetDefaultProvinceColor(sPid); }
|
||||
foreach (ProvinceId tPid in TargetedProvinces) { SetDefaultProvinceColor(tPid); }
|
||||
foreach (var commandProvince in ProvincesWithCommands) {
|
||||
SetDefaultProvinceColor(commandProvince);
|
||||
}
|
||||
|
||||
foreach (var pid in OverrideTargetedProvinces)
|
||||
{
|
||||
foreach (var pid in OverrideTargetedProvinces) {
|
||||
flashProvince(pid, TARGET_COLOR, 0.25f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedProvinceId is ProvinceId sPid)
|
||||
{
|
||||
} else {
|
||||
if (SelectedProvinceId is ProvinceId sPid) {
|
||||
flashProvince(sPid, SELECTION_COLOR, 1.0f);
|
||||
}
|
||||
foreach (ProvinceId tPid in TargetedProvinces)
|
||||
{
|
||||
foreach (ProvinceId tPid in TargetedProvinces) {
|
||||
flashProvince(tPid, TARGET_COLOR, 0.25f);
|
||||
}
|
||||
foreach (var commandProvince in ProvincesWithCommands)
|
||||
{
|
||||
foreach (var commandProvince in ProvincesWithCommands) {
|
||||
flashProvince(commandProvince, COMMAND_AVAILABLE_COLOR, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void flashProvince(ProvinceId provinceId, Color flashColor, float duration)
|
||||
{
|
||||
SetProvinceColor(provinceId,
|
||||
private void flashProvince(ProvinceId provinceId, Color flashColor, float duration) {
|
||||
SetProvinceColor(
|
||||
provinceId,
|
||||
Color.Lerp(
|
||||
colorForProvince(Model.Provinces[provinceId]),
|
||||
flashColor,
|
||||
Mathf.PingPong(Time.time, duration)
|
||||
));
|
||||
Mathf.PingPong(Time.time, duration)));
|
||||
}
|
||||
|
||||
public void OnLeftClick(Vector2 position)
|
||||
{
|
||||
SelectedProvinceId = ProvinceFromPoint(position);
|
||||
}
|
||||
public void OnLeftClick(Vector2 position) { SelectedProvinceId = ProvinceFromPoint(position); }
|
||||
|
||||
public void OnRightClick(Vector2 position)
|
||||
{
|
||||
if (ProvinceFromPoint(position) is ProvinceId pid)
|
||||
{
|
||||
public void OnRightClick(Vector2 position) {
|
||||
if (ProvinceFromPoint(position) is ProvinceId pid) {
|
||||
TargetedProvinces = new List<ProvinceId> { pid };
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
TargetedProvinces.Clear();
|
||||
}
|
||||
TargetedProvincesChangedCallback.Invoke(TargetedProvinces);
|
||||
}
|
||||
|
||||
void SetUpCenterText(ProvinceId? maybeProvinceId, Color color)
|
||||
{
|
||||
void SetUpCenterText(ProvinceId? maybeProvinceId, Color color) {
|
||||
provinceNameText.color = color;
|
||||
provinceOwnerText.color = color;
|
||||
if (maybeProvinceId is ProvinceId pid)
|
||||
{
|
||||
if (maybeProvinceId is ProvinceId pid) {
|
||||
var province = Model.Provinces[pid];
|
||||
provinceNameText.text = province.Name;
|
||||
|
||||
if (province.RulingFactionId is FactionId fid)
|
||||
{
|
||||
if (province.RulingFactionId is FactionId fid) {
|
||||
provinceOwnerText.text = Model.FactionName(fid);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
provinceOwnerText.text = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
provinceNameText.text = "";
|
||||
provinceOwnerText.text = "";
|
||||
}
|
||||
|
||||
@@ -3,25 +3,21 @@ using TMPro;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class NotificationPanel : PopupPanelController
|
||||
{
|
||||
public class NotificationPanel : PopupPanelController {
|
||||
public Button DismissAllButton;
|
||||
public TMP_Text DismissOneButtonText;
|
||||
|
||||
private class Note
|
||||
{
|
||||
private class Note {
|
||||
public string Title { get; }
|
||||
public string Text { get; private set; }
|
||||
public string FirstImagePath { get; private set; }
|
||||
public string SecondImagePath { get; private set; }
|
||||
public List<ProvinceId> ProvinceIds { get; private set; }
|
||||
|
||||
public Note(string title, string text, List<ProvinceId> provinceIds)
|
||||
{
|
||||
public Note(string title, string text, List<ProvinceId> provinceIds) {
|
||||
Title = title;
|
||||
Text = text;
|
||||
ProvinceIds = provinceIds;
|
||||
@@ -29,8 +25,12 @@ namespace eagle
|
||||
SecondImagePath = null;
|
||||
}
|
||||
|
||||
public Note(string title, string text, List<ProvinceId> provinceIds, string firstImagePath, string secondImagePath)
|
||||
{
|
||||
public Note(
|
||||
string title,
|
||||
string text,
|
||||
List<ProvinceId> provinceIds,
|
||||
string firstImagePath,
|
||||
string secondImagePath) {
|
||||
Title = title;
|
||||
Text = text;
|
||||
ProvinceIds = provinceIds;
|
||||
@@ -38,8 +38,7 @@ namespace eagle
|
||||
SecondImagePath = secondImagePath;
|
||||
}
|
||||
|
||||
public void Append(string text, List<ProvinceId> provinceIds)
|
||||
{
|
||||
public void Append(string text, List<ProvinceId> provinceIds) {
|
||||
Text += "\n" + text;
|
||||
ProvinceIds.AddRange(provinceIds);
|
||||
}
|
||||
@@ -47,66 +46,58 @@ namespace eagle
|
||||
|
||||
private Queue<Note> notes = new Queue<Note>();
|
||||
|
||||
private void SetPopupInfos()
|
||||
{
|
||||
PopupInfos = notes.Select(note => new PopupInfo
|
||||
{
|
||||
private void SetPopupInfos() {
|
||||
PopupInfos = notes.Select(note => new PopupInfo {
|
||||
titleText = note.Title,
|
||||
mainText = note.Text,
|
||||
affectedProvinceIds = note.ProvinceIds,
|
||||
firstHeroPath = note.FirstImagePath,
|
||||
secondHeroPath = note.SecondImagePath
|
||||
}).ToList();
|
||||
})
|
||||
.ToList();
|
||||
|
||||
SetUpPanel();
|
||||
|
||||
if (PopupInfos.Count == 1)
|
||||
{
|
||||
if (PopupInfos.Count == 1) {
|
||||
DismissAllButton.gameObject.SetActive(false);
|
||||
DismissOneButtonText.text = "Done";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DismissAllButton.gameObject.SetActive(true);
|
||||
DismissOneButtonText.text = "Dismiss";
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNote(string title, string text, List<ProvinceId> provinceIds)
|
||||
{
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
public void AddNote(string title, string text, List<ProvinceId> provinceIds) {
|
||||
MainQueue.Q.Enqueue(() => {
|
||||
var existingNote = notes.FirstOrDefault(n => n.Title == title);
|
||||
|
||||
if (existingNote == null)
|
||||
{
|
||||
if (existingNote == null) {
|
||||
notes.Enqueue(new Note(title, text, provinceIds));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
existingNote.Append(text, provinceIds);
|
||||
}
|
||||
SetPopupInfos();
|
||||
});
|
||||
}
|
||||
|
||||
public void AddNote(string title, string text, List<ProvinceId> provinceIds, string firstImagePath, string secondImagePath)
|
||||
{
|
||||
MainQueue.Q.Enqueue(() =>
|
||||
{
|
||||
public void AddNote(
|
||||
string title,
|
||||
string text,
|
||||
List<ProvinceId> provinceIds,
|
||||
string firstImagePath,
|
||||
string secondImagePath) {
|
||||
MainQueue.Q.Enqueue(() => {
|
||||
notes.Enqueue(new Note(title, text, provinceIds, firstImagePath, secondImagePath));
|
||||
SetPopupInfos();
|
||||
});
|
||||
}
|
||||
|
||||
public void DismissButtonClicked()
|
||||
{
|
||||
public void DismissButtonClicked() {
|
||||
notes.Dequeue();
|
||||
SetPopupInfos();
|
||||
}
|
||||
|
||||
public void DismissAllClicked()
|
||||
{
|
||||
public void DismissAllClicked() {
|
||||
notes.Clear();
|
||||
SetPopupInfos();
|
||||
}
|
||||
|
||||
+12
-29
@@ -5,10 +5,8 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static Net.Eagle0.Eagle.Api.OrganizeTroopsAvailableCommand.Types;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class OrganizeExtrasTable : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class OrganizeExtrasTable : MonoBehaviour {
|
||||
public RawImage unavailableImage;
|
||||
public GameObject minimumAgricultureRow;
|
||||
public GameObject minimumEconomyRow;
|
||||
@@ -16,49 +14,34 @@ namespace eagle
|
||||
public TMP_Text minimumEconomy;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
void Update() {}
|
||||
|
||||
}
|
||||
|
||||
public void Set(bool allowed, BattalionTypeStatus battalionTypeStatus, int agriculture, int economy)
|
||||
{
|
||||
public void
|
||||
Set(bool allowed, BattalionTypeStatus battalionTypeStatus, int agriculture, int economy) {
|
||||
var parent = gameObject.transform.parent;
|
||||
parent.GetComponentInChildren<Button>().interactable = allowed;
|
||||
unavailableImage.gameObject.SetActive(!allowed);
|
||||
|
||||
var color = parent.GetComponentInChildren<RawImage>().color;
|
||||
if (allowed)
|
||||
{
|
||||
if (allowed) {
|
||||
color.a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
color.a = 70;
|
||||
|
||||
if (agriculture < battalionTypeStatus.MinimumAgriculture)
|
||||
{
|
||||
if (agriculture < battalionTypeStatus.MinimumAgriculture) {
|
||||
minimumAgriculture.text = battalionTypeStatus.MinimumAgriculture.ToString();
|
||||
minimumAgricultureRow.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
minimumAgricultureRow.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (economy < battalionTypeStatus.MinimumEconomy)
|
||||
{
|
||||
if (economy < battalionTypeStatus.MinimumEconomy) {
|
||||
minimumEconomy.text = battalionTypeStatus.MinimumEconomy.ToString();
|
||||
minimumEconomyRow.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
minimumEconomyRow.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class PanelPositions : MonoBehaviour
|
||||
{
|
||||
public class PanelPositions : MonoBehaviour {
|
||||
public Canvas canvas;
|
||||
public RectTransform mapPanelTransform;
|
||||
|
||||
public Rect MapRect
|
||||
{
|
||||
get
|
||||
{
|
||||
public Rect MapRect {
|
||||
get {
|
||||
Vector3[] corners = new Vector3[4];
|
||||
mapPanelTransform.GetWorldCorners(corners);
|
||||
Vector3 topLeft = new Vector3(corners[1].x, canvas.pixelRect.height - corners[1].y, corners[1].z);
|
||||
Vector3 topLeft =
|
||||
new Vector3(corners[1].x, canvas.pixelRect.height - corners[1].y, corners[1].z);
|
||||
|
||||
Vector2 scaledSize = new Vector2(canvas.scaleFactor * mapPanelTransform.rect.size.x, canvas.scaleFactor * mapPanelTransform.rect.size.y);
|
||||
Vector2 scaledSize = new Vector2(
|
||||
canvas.scaleFactor * mapPanelTransform.rect.size.x,
|
||||
canvas.scaleFactor* mapPanelTransform.rect.size.y);
|
||||
return new Rect(topLeft, scaledSize);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -1,19 +1,15 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class PopupCanvasController : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class PopupCanvasController : MonoBehaviour {
|
||||
public GameObject modalBlocker;
|
||||
public GameObject panel;
|
||||
|
||||
void Update()
|
||||
{
|
||||
void Update() {
|
||||
bool enable = false;
|
||||
|
||||
foreach (var controller in panel.GetComponentsInChildren<PopupPanelController>())
|
||||
{
|
||||
foreach (var controller in panel.GetComponentsInChildren<PopupPanelController>()) {
|
||||
bool hasInfo = controller.HasInfo;
|
||||
enable = enable || hasInfo;
|
||||
controller.gameObject.SetActive(hasInfo);
|
||||
@@ -22,8 +18,7 @@ namespace eagle
|
||||
panel.SetActive(enable);
|
||||
}
|
||||
|
||||
public void SetChildActive(bool val)
|
||||
{
|
||||
public void SetChildActive(bool val) {
|
||||
// if (val)
|
||||
//{
|
||||
// gameObject.SetActive(true);
|
||||
|
||||
+24
-52
@@ -4,12 +4,10 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = System.Int32;
|
||||
|
||||
public class PopupPanelController : MonoBehaviour
|
||||
{
|
||||
public class PopupPanelController : MonoBehaviour {
|
||||
public PopupCanvasController canvas;
|
||||
public MapController mapController;
|
||||
public TextMeshProUGUI textField;
|
||||
@@ -20,8 +18,7 @@ namespace eagle
|
||||
public Button acceptButton;
|
||||
public Button rejectButton;
|
||||
|
||||
public struct PopupInfo
|
||||
{
|
||||
public struct PopupInfo {
|
||||
public string titleText;
|
||||
public string mainText;
|
||||
public string firstHeroPath;
|
||||
@@ -30,11 +27,9 @@ namespace eagle
|
||||
}
|
||||
|
||||
List<PopupInfo> _popupInfos = new List<PopupInfo>();
|
||||
protected List<PopupInfo> PopupInfos
|
||||
{
|
||||
protected List<PopupInfo> PopupInfos {
|
||||
get => _popupInfos;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_popupInfos = value;
|
||||
SetUpPanel();
|
||||
}
|
||||
@@ -44,59 +39,40 @@ namespace eagle
|
||||
|
||||
protected int DisplayedIndex { get; private set; }
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetUpPanel();
|
||||
void Start() { SetUpPanel(); }
|
||||
|
||||
void OnDisable() {
|
||||
if (_popupInfos.Count == 0) { canvas.SetChildActive(false); }
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (_popupInfos.Count == 0)
|
||||
{
|
||||
canvas.SetChildActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
virtual protected void SetUpPanel()
|
||||
{
|
||||
if (_popupInfos.Count == 0)
|
||||
{
|
||||
virtual protected void SetUpPanel() {
|
||||
if (_popupInfos.Count == 0) {
|
||||
mapController.OverrideTargetedProvinces = new List<ProvinceId>();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DisplayedIndex >= _popupInfos.Count)
|
||||
{
|
||||
DisplayedIndex = 0;
|
||||
}
|
||||
} else {
|
||||
if (DisplayedIndex >= _popupInfos.Count) { DisplayedIndex = 0; }
|
||||
if (nextButton) nextButton.gameObject.SetActive(PopupInfos.Count > 1);
|
||||
|
||||
title.text = PopupInfos[DisplayedIndex].titleText;
|
||||
textField.text = PopupInfos[DisplayedIndex].mainText;
|
||||
mapController.OverrideTargetedProvinces = PopupInfos[DisplayedIndex].affectedProvinceIds;
|
||||
mapController.OverrideTargetedProvinces =
|
||||
PopupInfos[DisplayedIndex].affectedProvinceIds;
|
||||
|
||||
if (string.IsNullOrEmpty(PopupInfos[DisplayedIndex].firstHeroPath))
|
||||
{
|
||||
if (firstImage != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(PopupInfos[DisplayedIndex].firstHeroPath)) {
|
||||
if (firstImage != null) {
|
||||
firstImage.gameObject.SetActive(false);
|
||||
secondImage.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
var fetcher = GetComponentInParent<AWSResourceFetcher>(includeInactive: true);
|
||||
firstImage.texture = fetcher.GetImage(PopupInfos[DisplayedIndex].firstHeroPath);
|
||||
firstImage.gameObject.SetActive(true);
|
||||
|
||||
if (string.IsNullOrEmpty(PopupInfos[DisplayedIndex].secondHeroPath))
|
||||
{
|
||||
if (string.IsNullOrEmpty(PopupInfos[DisplayedIndex].secondHeroPath)) {
|
||||
secondImage.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
secondImage.texture = fetcher.GetImage(PopupInfos[DisplayedIndex].secondHeroPath);
|
||||
} else {
|
||||
secondImage.texture =
|
||||
fetcher.GetImage(PopupInfos[DisplayedIndex].secondHeroPath);
|
||||
secondImage.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
@@ -108,13 +84,9 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public void NextButtonClicked()
|
||||
{
|
||||
public void NextButtonClicked() {
|
||||
DisplayedIndex++;
|
||||
if (DisplayedIndex >= PopupInfos.Count)
|
||||
{
|
||||
DisplayedIndex = 0;
|
||||
}
|
||||
if (DisplayedIndex >= PopupInfos.Count) { DisplayedIndex = 0; }
|
||||
SetUpPanel();
|
||||
}
|
||||
}
|
||||
|
||||
+79
-105
@@ -9,19 +9,15 @@ using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using HeroId = Int32;
|
||||
using FactionId = Int32;
|
||||
|
||||
public class ProvinceInfoPanelController : MonoBehaviour
|
||||
{
|
||||
public class ProvinceInfoPanelController : MonoBehaviour {
|
||||
private GameModel _model;
|
||||
public GameModel Model
|
||||
{
|
||||
private get => _model;
|
||||
set
|
||||
{
|
||||
public GameModel Model { private
|
||||
get => _model;
|
||||
set {
|
||||
_model = value;
|
||||
panel.SetActive(_model != null && _provinceView != null);
|
||||
}
|
||||
@@ -58,95 +54,88 @@ namespace eagle
|
||||
|
||||
private ProvinceView _provinceView;
|
||||
|
||||
private void SetHeadshotToHeroId(HeroId hid)
|
||||
{
|
||||
private void SetHeadshotToHeroId(HeroId hid) {
|
||||
var rulingHero = _model.Heroes[hid];
|
||||
|
||||
if (rulingHero.ImagePath is String path)
|
||||
{
|
||||
Texture2D headshotTexture = GetComponentInParent<AWSResourceFetcher>().GetImage(path);
|
||||
if (rulingHero.ImagePath is String path) {
|
||||
Texture2D headshotTexture =
|
||||
GetComponentInParent<AWSResourceFetcher>().GetImage(path);
|
||||
HeadshotImage.texture = headshotTexture;
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateHeadshot()
|
||||
{
|
||||
private void PopulateHeadshot() {
|
||||
HeadshotImage.texture = null;
|
||||
Color c = HeadshotImage.color;
|
||||
c.a = 1.0f;
|
||||
if (_provinceView?.FullInfo?.RulingHeroId is HeroId rulingHid)
|
||||
{
|
||||
if (_provinceView?.FullInfo?.RulingHeroId is HeroId rulingHid) {
|
||||
SetHeadshotToHeroId(rulingHid);
|
||||
var rulingHero = _model.Heroes[rulingHid];
|
||||
}
|
||||
else if (_provinceView?.RulingFactionId is FactionId fid)
|
||||
{
|
||||
} else if (_provinceView?.RulingFactionId is FactionId fid) {
|
||||
SetHeadshotToHeroId(_model.ActiveFactions[fid].FactionHeadId);
|
||||
|
||||
c.a = 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
HeadshotImage.texture = null;
|
||||
}
|
||||
HeadshotImage.color = c;
|
||||
}
|
||||
|
||||
private void PopulateDetails()
|
||||
{
|
||||
private void PopulateDetails() {
|
||||
bool ownProvince = _provinceView.RulingFactionId == Model.PlayerId;
|
||||
var underAttack = ownProvince && Province.KnownIncomingArmies.Any(x => x.FactionId != Model.PlayerId && x.HeroCount > 0);
|
||||
var underAttack =
|
||||
ownProvince && Province.KnownIncomingArmies.Any(
|
||||
x => x.FactionId != Model.PlayerId && x.HeroCount > 0);
|
||||
AsOfField.gameObject.SetActive(false);
|
||||
ProvinceEventsField.gameObject.SetActive(false);
|
||||
|
||||
if (ownProvince)
|
||||
{
|
||||
panel.GetComponent<Image>().color = underAttack ? GUIUtils.UnderAttackPanelColor : GUIUtils.PanelColor;
|
||||
if (ownProvince) {
|
||||
panel.GetComponent<Image>().color =
|
||||
underAttack ? GUIUtils.UnderAttackPanelColor : GUIUtils.PanelColor;
|
||||
UnderAttackField.gameObject.SetActive(underAttack);
|
||||
}
|
||||
else if (Province.AsOf != null)
|
||||
{
|
||||
} else if (Province.AsOf != null) {
|
||||
AsOfField.text = $"As of {DisplayNames.DateString(Province.AsOf)}";
|
||||
AsOfField.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
bool overFoodCap = Province.FullInfo.Food > Province.FullInfo.FoodCap;
|
||||
bool overGoldCap = Province.FullInfo.Gold > Province.FullInfo.GoldCap;
|
||||
GoldField.text = $"{GUIUtils.PossiblyColoredString(overGoldCap, Color.red, Province.FullInfo.Gold.ToString())} / {Province.FullInfo.GoldCap}";
|
||||
FoodField.text = $"{GUIUtils.PossiblyColoredString(overFoodCap, Color.red, Province.FullInfo.Food.ToString())} / {Province.FullInfo.FoodCap}";
|
||||
GoldField.text =
|
||||
$"{GUIUtils.PossiblyColoredString(overGoldCap, Color.red, Province.FullInfo.Gold.ToString())} / {Province.FullInfo.GoldCap}";
|
||||
FoodField.text =
|
||||
$"{GUIUtils.PossiblyColoredString(overFoodCap, Color.red, Province.FullInfo.Food.ToString())} / {Province.FullInfo.FoodCap}";
|
||||
ConsumedField.text = $"{Province.FullInfo.FoodConsumption}";
|
||||
|
||||
EconomyField.text = $"{Province.FullInfo.Economy}";
|
||||
if (Province.FullInfo.EconomyDevastation > 0)
|
||||
{
|
||||
var devastatedEconomy = $"{Math.Max(0.0, Province.FullInfo.Economy - Province.FullInfo.EconomyDevastation)}";
|
||||
if (Province.FullInfo.EconomyDevastation > 0) {
|
||||
var devastatedEconomy =
|
||||
$"{Math.Max(0.0, Province.FullInfo.Economy - Province.FullInfo.EconomyDevastation)}";
|
||||
EconomyField.text += $" ({GUIUtils.ColoredString(Color.red, devastatedEconomy)})";
|
||||
}
|
||||
|
||||
AgricultureField.text = $"{Province.FullInfo.Agriculture}";
|
||||
if (Province.FullInfo.AgricultureDevastation > 0)
|
||||
{
|
||||
var devastatedAgriculture = $"{Math.Max(0.0, Province.FullInfo.Agriculture - Province.FullInfo.AgricultureDevastation)}";
|
||||
AgricultureField.text += $" ({GUIUtils.ColoredString(Color.red, devastatedAgriculture)})";
|
||||
if (Province.FullInfo.AgricultureDevastation > 0) {
|
||||
var devastatedAgriculture =
|
||||
$"{Math.Max(0.0, Province.FullInfo.Agriculture - Province.FullInfo.AgricultureDevastation)}";
|
||||
AgricultureField.text +=
|
||||
$" ({GUIUtils.ColoredString(Color.red, devastatedAgriculture)})";
|
||||
}
|
||||
|
||||
InfrastructureField.text = $"{Province.FullInfo.Infrastructure}";
|
||||
if (Province.FullInfo.InfrastructureDevastation > 0)
|
||||
{
|
||||
var devastatedInfrastructure = $"{Math.Max(0.0, Province.FullInfo.Infrastructure - Province.FullInfo.InfrastructureDevastation)}";
|
||||
InfrastructureField.text += $" ({GUIUtils.ColoredString(Color.red, devastatedInfrastructure)})";
|
||||
if (Province.FullInfo.InfrastructureDevastation > 0) {
|
||||
var devastatedInfrastructure =
|
||||
$"{Math.Max(0.0, Province.FullInfo.Infrastructure - Province.FullInfo.InfrastructureDevastation)}";
|
||||
InfrastructureField.text +=
|
||||
$" ({GUIUtils.ColoredString(Color.red, devastatedInfrastructure)})";
|
||||
}
|
||||
|
||||
SupportField.text = $"{GUIUtils.ConditionString(Province.FullInfo.Support)}";
|
||||
|
||||
var heroCount = Province.FullInfo.RulingFactionHeroIds.Count;
|
||||
var heroCountString = $"{heroCount}";
|
||||
if (Province.FullInfo.HeroCap >= Province.FullInfo.RulingFactionHeroIds.Count)
|
||||
{
|
||||
if (Province.FullInfo.HeroCap >= Province.FullInfo.RulingFactionHeroIds.Count) {
|
||||
CommandersField.text = heroCountString;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CommandersField.text = $"{GUIUtils.ColoredString(Color.red, heroCountString)}";
|
||||
}
|
||||
FreeHeroesField.text = $"{Province.FullInfo?.UnaffiliatedHeroes.Count ?? 0}";
|
||||
@@ -156,19 +145,17 @@ namespace eagle
|
||||
CastleCountField.text = $"{Province.FullInfo.CastleCount}";
|
||||
|
||||
var eventTexts = new List<String>();
|
||||
foreach (var ae in Province.KnownEvents)
|
||||
{
|
||||
foreach (var ae in Province.KnownEvents) {
|
||||
ProvinceEventsField.gameObject.SetActive(true);
|
||||
|
||||
switch (ae.SealedValueCase)
|
||||
{
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase.BeastsEvent:
|
||||
{
|
||||
switch (ae.SealedValueCase) {
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase.BeastsEvent: {
|
||||
var beastType = DisplayNames.BeastTypeName(ae.BeastsEvent.BeastType);
|
||||
eventTexts.Add($"{ae.BeastsEvent.Count} {beastType} are disrupting trade!");
|
||||
break;
|
||||
}
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase.ImminentRiotEvent:
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase
|
||||
.ImminentRiotEvent:
|
||||
eventTexts.Add("The people are angry! A riot is imminent!");
|
||||
break;
|
||||
|
||||
@@ -191,23 +178,19 @@ namespace eagle
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase.EpidemicEvent:
|
||||
eventTexts.Add("A terrible plague!");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
ProvinceEventsField.text = String.Join(" ", eventTexts);
|
||||
}
|
||||
|
||||
public ProvinceView Province
|
||||
{
|
||||
public ProvinceView Province {
|
||||
get => _provinceView;
|
||||
set
|
||||
{
|
||||
set {
|
||||
DiplomacyInfoField.gameObject.SetActive(false);
|
||||
ProvinceDetailsContainer.SetActive(false);
|
||||
|
||||
_provinceView = value;
|
||||
if (_provinceView != null)
|
||||
{
|
||||
if (_provinceView != null) {
|
||||
panel.SetActive(true);
|
||||
|
||||
var ownProvince = Province.RulingFactionId == Model.PlayerId;
|
||||
@@ -215,58 +198,56 @@ namespace eagle
|
||||
|
||||
PopulateHeadshot();
|
||||
|
||||
if (hasFullInfo)
|
||||
{
|
||||
if (hasFullInfo) {
|
||||
PopulateDetails();
|
||||
|
||||
ProvinceDetailsContainer.SetActive(true);
|
||||
}
|
||||
|
||||
if (Province.RulingFactionId.HasValue)
|
||||
{
|
||||
if (Province.RulingFactionId.HasValue) {
|
||||
var faction = Model.MaybeDestroyedFaction(Province.RulingFactionId.Value);
|
||||
var rulingHeroName = hasFullInfo ? Model.Heroes[Province.FullInfo.RulingHeroId.Value].Name : "UNKNOWN";
|
||||
var rulingHeroName =
|
||||
hasFullInfo
|
||||
? Model.Heroes[Province.FullInfo.RulingHeroId.Value].Name
|
||||
: "UNKNOWN";
|
||||
|
||||
var rulerLabel = $"{rulingHeroName} ({faction.Name}" + (ownProvince ? $" {faction.Prestige})" : ")");
|
||||
if (hasFullInfo && Province.FullInfo.ProvinceOrders != Net.Eagle0.Eagle.Common.ProvinceOrderType.UnknownOrders)
|
||||
{
|
||||
rulerLabel += $" – {DisplayNames.ProvinceOrderTypeNames[Province.FullInfo.ProvinceOrders]}";
|
||||
var rulerLabel = $"{rulingHeroName} ({faction.Name}" +
|
||||
(ownProvince ? $" {faction.Prestige})" : ")");
|
||||
if (hasFullInfo &&
|
||||
Province.FullInfo.ProvinceOrders !=
|
||||
Net.Eagle0.Eagle.Common.ProvinceOrderType.UnknownOrders) {
|
||||
rulerLabel +=
|
||||
$" – {DisplayNames.ProvinceOrderTypeNames[Province.FullInfo.ProvinceOrders]}";
|
||||
}
|
||||
ProvinceNameField.text = Province.Name;
|
||||
ProvinceLeaderField.text = rulerLabel;
|
||||
|
||||
if (!hasFullInfo)
|
||||
{
|
||||
if (Model.PlayerId.HasValue)
|
||||
{
|
||||
if (!hasFullInfo) {
|
||||
if (Model.PlayerId.HasValue) {
|
||||
DiplomacyInfoField.text = "";
|
||||
foreach (var treaty in faction.Treaties)
|
||||
{
|
||||
if (treaty.TargetFactionId == Model.PlayerId)
|
||||
{
|
||||
DiplomacyInfoField.text += $"We have a treaty with them until {DisplayNames.DateString(treaty.EndDate)}.\n";
|
||||
foreach (var treaty in faction.Treaties) {
|
||||
if (treaty.TargetFactionId == Model.PlayerId) {
|
||||
DiplomacyInfoField.text +=
|
||||
$"We have a treaty with them until {DisplayNames.DateString(treaty.EndDate)}.\n";
|
||||
}
|
||||
}
|
||||
foreach (var offer in Model.MaybeDestroyedFaction(Model.PlayerId.Value).OutgoingOffers)
|
||||
{
|
||||
if (offer.TargetFactionId == faction.Id)
|
||||
{
|
||||
DiplomacyInfoField.text += $"We have a treaty offer en route to them.";
|
||||
foreach (var offer in Model
|
||||
.MaybeDestroyedFaction(Model.PlayerId.Value)
|
||||
.OutgoingOffers) {
|
||||
if (offer.TargetFactionId == faction.Id) {
|
||||
DiplomacyInfoField.text +=
|
||||
$"We have a treaty offer en route to them.";
|
||||
}
|
||||
}
|
||||
DiplomacyInfoField.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ProvinceNameField.text = Province.Name;
|
||||
ProvinceLeaderField.text = "Free Province";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
panel.SetActive(false);
|
||||
ProvinceDetailsContainer.SetActive(false);
|
||||
}
|
||||
@@ -274,20 +255,13 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
panel.SetActive(false);
|
||||
}
|
||||
void Start() { panel.SetActive(false); }
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
void Update() {
|
||||
if (Model == null) {
|
||||
panel.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
panel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,11 @@
|
||||
using System.Linq;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public static class ProvinceUtils
|
||||
{
|
||||
public static List<BattalionView> OrderedBattalions(ProvinceView province)
|
||||
{
|
||||
if (province == null || province.FullInfo == null)
|
||||
{
|
||||
return new List<BattalionView>();
|
||||
}
|
||||
return province.FullInfo.Battalions
|
||||
.OrderBy(b => b, BattalionUtils.BattalionComparer)
|
||||
namespace eagle {
|
||||
public static class ProvinceUtils {
|
||||
public static List<BattalionView> OrderedBattalions(ProvinceView province) {
|
||||
if (province == null || province.FullInfo == null) { return new List<BattalionView>(); }
|
||||
return province.FullInfo.Battalions.OrderBy(b => b, BattalionUtils.BattalionComparer)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,19 +7,16 @@ using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Shardok.Common;
|
||||
using Grpc.Core;
|
||||
|
||||
namespace eagle0
|
||||
{
|
||||
namespace eagle0 {
|
||||
using static Net.Eagle0.Eagle.Api.ShardokPlacementCommands.Types;
|
||||
using static Net.Eagle0.Eagle.Api.UpdateStreamRequest.Types;
|
||||
using GameId = Int64;
|
||||
using PlayerId = Int32;
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class RemoteEagleClient : EagleClientInterface
|
||||
{
|
||||
public class RemoteEagleClient : EagleClientInterface {
|
||||
private readonly double TIMEOUT_SECONDS = 55.0;
|
||||
private DateTime? GetDeadlineFromNow()
|
||||
{
|
||||
private DateTime? GetDeadlineFromNow() {
|
||||
return DateTime.UtcNow.AddSeconds(TIMEOUT_SECONDS);
|
||||
}
|
||||
|
||||
@@ -32,8 +29,12 @@ namespace eagle0
|
||||
|
||||
private Logger logger = Logger.connectionLogger;
|
||||
|
||||
public RemoteEagleClient(GameId gameId, Eagle.EagleClient client, Metadata creds, PlayerId? playerId, CancellationToken token)
|
||||
{
|
||||
public RemoteEagleClient(
|
||||
GameId gameId,
|
||||
Eagle.EagleClient client,
|
||||
Metadata creds,
|
||||
PlayerId? playerId,
|
||||
CancellationToken token) {
|
||||
grpcClient = client;
|
||||
GameId = gameId;
|
||||
PlayerId = playerId;
|
||||
@@ -41,36 +42,31 @@ namespace eagle0
|
||||
cancellationToken = token;
|
||||
}
|
||||
|
||||
public async Task<PostCommandResponse> PostCommand(long token, ProvinceId provinceId, SelectedCommand command)
|
||||
{
|
||||
var request = new PostCommandRequest
|
||||
{
|
||||
public async Task<PostCommandResponse>
|
||||
PostCommand(long token, ProvinceId provinceId, SelectedCommand command) {
|
||||
var request = new PostCommandRequest {
|
||||
GameId = GameId,
|
||||
Token = token,
|
||||
|
||||
Command = new UniversalCommand
|
||||
{
|
||||
EagleCommand = new EagleCommand
|
||||
{
|
||||
ProvinceId = provinceId,
|
||||
Command = command
|
||||
}
|
||||
Command =
|
||||
new UniversalCommand {
|
||||
EagleCommand =
|
||||
new EagleCommand { ProvinceId = provinceId, Command = command }
|
||||
}
|
||||
};
|
||||
return await grpcClient.PostCommandAsync(request);
|
||||
}
|
||||
|
||||
public async Task<PostCommandResponse> PostShardokCommand(string gameId, Int32 playerId, Int64 token, Int32 index)
|
||||
{
|
||||
var request = new PostCommandRequest
|
||||
{
|
||||
public async Task<PostCommandResponse>
|
||||
PostShardokCommand(string gameId, Int32 playerId, Int64 token, Int32 index) {
|
||||
var request = new PostCommandRequest {
|
||||
GameId = GameId,
|
||||
Token = token,
|
||||
|
||||
Command = new UniversalCommand
|
||||
{
|
||||
ShardokCommand = new ShardokCommand
|
||||
{
|
||||
Command =
|
||||
new UniversalCommand {
|
||||
ShardokCommand =
|
||||
new ShardokCommand {
|
||||
GameId = gameId,
|
||||
PlayerId = playerId,
|
||||
Token = token,
|
||||
@@ -81,10 +77,12 @@ namespace eagle0
|
||||
return await grpcClient.PostCommandAsync(request);
|
||||
}
|
||||
|
||||
public async Task<PostCommandResponse> PostShardokPlacementCommands(string gameId, Int32 playerId, List<ShardokPlacementCommand> placementCommands, Int64 token)
|
||||
{
|
||||
var sc = new ShardokPlacementCommands
|
||||
{
|
||||
public async Task<PostCommandResponse> PostShardokPlacementCommands(
|
||||
string gameId,
|
||||
Int32 playerId,
|
||||
List<ShardokPlacementCommand> placementCommands,
|
||||
Int64 token) {
|
||||
var sc = new ShardokPlacementCommands {
|
||||
GameId = gameId,
|
||||
PlayerId = playerId,
|
||||
Token = token
|
||||
@@ -92,52 +90,39 @@ namespace eagle0
|
||||
|
||||
sc.PlacementCommands.AddRange(placementCommands);
|
||||
|
||||
var request = new PostCommandRequest
|
||||
{
|
||||
var request = new PostCommandRequest {
|
||||
GameId = GameId,
|
||||
Token = token,
|
||||
|
||||
Command = new UniversalCommand
|
||||
{
|
||||
ShardokPlacementCommands = sc
|
||||
}
|
||||
Command = new UniversalCommand { ShardokPlacementCommands = sc }
|
||||
};
|
||||
return await grpcClient.PostCommandAsync(request);
|
||||
}
|
||||
|
||||
private Action<UpdateStreamResponse, StatusCode> repeatedCallback = null;
|
||||
|
||||
private async Task<bool> handleStreamingCall()
|
||||
{
|
||||
try
|
||||
{
|
||||
private async Task<bool> handleStreamingCall() {
|
||||
try {
|
||||
AsyncServerStreamingCall<UpdateStreamResponse> sc = null;
|
||||
lock (this)
|
||||
{
|
||||
sc = streamingCall;
|
||||
}
|
||||
while (sc != null && await sc.ResponseStream.MoveNext(cancellationToken))
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (repeatedCallback != null)
|
||||
{
|
||||
lock (this) { sc = streamingCall; }
|
||||
while (sc != null && await sc.ResponseStream.MoveNext(cancellationToken)) {
|
||||
lock (this) {
|
||||
if (repeatedCallback != null) {
|
||||
var current = sc.ResponseStream.Current;
|
||||
logger.LogLine($" Got an update of type {current.ResponseDetailsCase}");
|
||||
logger.LogLine(
|
||||
$" Got an update of type {current.ResponseDetailsCase}");
|
||||
|
||||
if (current.ResponseDetailsCase == UpdateStreamResponse.ResponseDetailsOneofCase.ErrorResponse)
|
||||
{
|
||||
if (current.ResponseDetailsCase ==
|
||||
UpdateStreamResponse.ResponseDetailsOneofCase.ErrorResponse) {
|
||||
logger.LogLine("It's an error response!");
|
||||
MainQueue.Q.Enqueue(() => repeatedCallback.Invoke(null, StatusCode.Cancelled));
|
||||
}
|
||||
else
|
||||
{
|
||||
MainQueue.Q.Enqueue(() => repeatedCallback.Invoke(current, StatusCode.OK));
|
||||
MainQueue.Q.Enqueue(
|
||||
() => repeatedCallback.Invoke(null, StatusCode.Cancelled));
|
||||
} else {
|
||||
MainQueue.Q.Enqueue(
|
||||
() => repeatedCallback.Invoke(current, StatusCode.OK));
|
||||
}
|
||||
sc = streamingCall;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logger.LogLine("calling streamingCall.Dispose()");
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
@@ -147,33 +132,24 @@ namespace eagle0
|
||||
}
|
||||
|
||||
logger.LogLine("How did we get here? This is not my beautiful wife!");
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
switch (e.StatusCode)
|
||||
{
|
||||
} catch (RpcException e) {
|
||||
lock (this) {
|
||||
switch (e.StatusCode) {
|
||||
case StatusCode.Cancelled:
|
||||
case StatusCode.Internal:
|
||||
logger.LogLine($"Got exception {e}");
|
||||
break;
|
||||
case StatusCode.Internal: logger.LogLine($"Got exception {e}"); break;
|
||||
|
||||
case StatusCode.DeadlineExceeded:
|
||||
logger.LogLine("Got DeadlineExceeded");
|
||||
break;
|
||||
|
||||
case StatusCode.Unavailable:
|
||||
logger.LogLine("Got Unavailable");
|
||||
break;
|
||||
case StatusCode.Unavailable: logger.LogLine("Got Unavailable"); break;
|
||||
|
||||
default:
|
||||
logger.LogLine($"Something went very wrong, caught exception {e}");
|
||||
break;
|
||||
}
|
||||
|
||||
if (repeatedCallback != null)
|
||||
{
|
||||
if (repeatedCallback != null) {
|
||||
MainQueue.Q.Enqueue(() => repeatedCallback.Invoke(null, e.StatusCode));
|
||||
}
|
||||
return false;
|
||||
@@ -183,12 +159,13 @@ namespace eagle0
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> RegisterForUpdates(Action<UpdateStreamResponse, StatusCode> rc, int lastUnfilteredResultCount, List<ShardokViewStatus> shardokViewStatuses)
|
||||
{
|
||||
public async Task<bool> RegisterForUpdates(
|
||||
Action<UpdateStreamResponse, StatusCode> rc,
|
||||
int lastUnfilteredResultCount,
|
||||
List<ShardokViewStatus> shardokViewStatuses) {
|
||||
logger.LogLine("Calling StreamUpdates...");
|
||||
|
||||
var request = new UpdateStreamRequest
|
||||
{
|
||||
var request = new UpdateStreamRequest {
|
||||
GameId = GameId,
|
||||
UnfilteredResultCount = lastUnfilteredResultCount
|
||||
};
|
||||
@@ -199,10 +176,8 @@ namespace eagle0
|
||||
request: request,
|
||||
headers: Credentials,
|
||||
deadline: GetDeadlineFromNow(),
|
||||
cancellationToken: cancellationToken))
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
cancellationToken: cancellationToken)) {
|
||||
lock (this) {
|
||||
repeatedCallback = rc;
|
||||
streamingCall = call;
|
||||
}
|
||||
@@ -211,23 +186,19 @@ namespace eagle0
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterForUpdates()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
public void UnregisterForUpdates() {
|
||||
lock (this) {
|
||||
repeatedCallback = null;
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
}
|
||||
}
|
||||
|
||||
public HexMap GetHexMap(string mapName)
|
||||
{
|
||||
public HexMap GetHexMap(string mapName) {
|
||||
return grpcClient.GetHexMap(new HexMapRequest { MapName = mapName }).Map;
|
||||
}
|
||||
|
||||
public async Task<HexMap> GetHexMapAsync(string mapName)
|
||||
{
|
||||
public async Task<HexMap> GetHexMapAsync(string mapName) {
|
||||
return (await grpcClient.GetHexMapAsync(new HexMapRequest { MapName = mapName })).Map;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-60
@@ -5,10 +5,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class ArmTroopsRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class ArmTroopsRowController : TableRowController {
|
||||
public RawImage battalionImage;
|
||||
public TMP_Text oldArmamentLabel;
|
||||
public TMP_Text newArmamentLabel;
|
||||
@@ -26,74 +24,32 @@ namespace eagle
|
||||
public Action ResetButtonClickedCallback;
|
||||
public Action MaxButtonClickedCallback;
|
||||
|
||||
public Texture BattalionImage
|
||||
{
|
||||
set => battalionImage.texture = value;
|
||||
}
|
||||
public Texture BattalionImage { set => battalionImage.texture = value; }
|
||||
|
||||
public double CostPerPoint
|
||||
{
|
||||
set => costPerPointLabel.text = value.ToString("0.##");
|
||||
}
|
||||
public double CostPerPoint { set => costPerPointLabel.text = value.ToString("0.##"); }
|
||||
|
||||
public double OldArmament
|
||||
{
|
||||
set => oldArmamentLabel.text = Math.Floor(value).ToString();
|
||||
}
|
||||
public double OldArmament { set => oldArmamentLabel.text = Math.Floor(value).ToString(); }
|
||||
|
||||
public double NewArmament
|
||||
{
|
||||
set => newArmamentLabel.text = Math.Floor(value).ToString();
|
||||
}
|
||||
public double NewArmament { set => newArmamentLabel.text = Math.Floor(value).ToString(); }
|
||||
|
||||
public int Size
|
||||
{
|
||||
set => sizeLabel.text = value.ToString();
|
||||
}
|
||||
public int Size { set => sizeLabel.text = value.ToString(); }
|
||||
|
||||
public string Name
|
||||
{
|
||||
set => nameLabel.text = value;
|
||||
}
|
||||
public string Name { set => nameLabel.text = value; }
|
||||
|
||||
public bool AllowPlus
|
||||
{
|
||||
set => plusButton.interactable = value;
|
||||
}
|
||||
public bool AllowPlus { set => plusButton.interactable = value; }
|
||||
|
||||
public bool AllowMinus
|
||||
{
|
||||
set => minusButton.interactable = value;
|
||||
}
|
||||
public bool AllowMinus { set => minusButton.interactable = value; }
|
||||
|
||||
public bool AllowReset
|
||||
{
|
||||
set => resetButton.interactable = value;
|
||||
}
|
||||
public bool AllowReset { set => resetButton.interactable = value; }
|
||||
|
||||
public bool AllowMax
|
||||
{
|
||||
set => maxButton.interactable = value;
|
||||
}
|
||||
public bool AllowMax { set => maxButton.interactable = value; }
|
||||
|
||||
public void PlusButtonClicked()
|
||||
{
|
||||
PlusButtonClickedCallback();
|
||||
}
|
||||
public void PlusButtonClicked() { PlusButtonClickedCallback(); }
|
||||
|
||||
public void MinusButtonClicked()
|
||||
{
|
||||
MinusButtonClickedCallback();
|
||||
}
|
||||
public void MinusButtonClicked() { MinusButtonClickedCallback(); }
|
||||
|
||||
public void ResetButtonClicked()
|
||||
{
|
||||
ResetButtonClickedCallback();
|
||||
}
|
||||
public void ResetButtonClicked() { ResetButtonClickedCallback(); }
|
||||
|
||||
public void MaxButtonClicked()
|
||||
{
|
||||
MaxButtonClickedCallback();
|
||||
}
|
||||
public void MaxButtonClicked() { MaxButtonClickedCallback(); }
|
||||
}
|
||||
}
|
||||
|
||||
+6
-16
@@ -3,28 +3,18 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class AvailableHeroTableRow : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class AvailableHeroTableRow : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public TMP_Text heroName;
|
||||
|
||||
public Texture ProfessionImage
|
||||
{
|
||||
set
|
||||
{
|
||||
public Texture ProfessionImage {
|
||||
set {
|
||||
professionImage.texture = value;
|
||||
if (value == null)
|
||||
{
|
||||
professionImage.color = Color.clear;
|
||||
}
|
||||
if (value == null) { professionImage.color = Color.clear; }
|
||||
}
|
||||
}
|
||||
|
||||
public string HeroName
|
||||
{
|
||||
set => heroName.text = value;
|
||||
}
|
||||
public string HeroName { set => heroName.text = value; }
|
||||
}
|
||||
}
|
||||
+5
-14
@@ -2,10 +2,8 @@
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public abstract class BattalionDisplayInfo
|
||||
{
|
||||
namespace eagle {
|
||||
public abstract class BattalionDisplayInfo {
|
||||
public Texture Image { get; }
|
||||
public double Cost { get; }
|
||||
public int Capacity { get; }
|
||||
@@ -19,26 +17,19 @@ namespace eagle
|
||||
|
||||
public bool Open { get; set; }
|
||||
|
||||
public BattalionDisplayInfo(Texture image, double cost, int capacity)
|
||||
{
|
||||
public BattalionDisplayInfo(Texture image, double cost, int capacity) {
|
||||
Image = image;
|
||||
Cost = cost;
|
||||
Capacity = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public struct BattalionComponent
|
||||
{
|
||||
public struct BattalionComponent {
|
||||
public int count;
|
||||
public double armament;
|
||||
public double training;
|
||||
|
||||
public enum ComponentSource
|
||||
{
|
||||
originalTroops,
|
||||
mergedTroops,
|
||||
newTroops
|
||||
}
|
||||
public enum ComponentSource { originalTroops, mergedTroops, newTroops }
|
||||
|
||||
public ComponentSource? source;
|
||||
}
|
||||
|
||||
+8
-13
@@ -3,25 +3,20 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class BattalionRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class BattalionRowController : TableRowController {
|
||||
public RawImage battalionImage;
|
||||
public TMP_Text sizeLabel;
|
||||
public TMP_Text trainingLabel;
|
||||
public TMP_Text armamentLabel;
|
||||
public TMP_Text battalionNameLabel;
|
||||
|
||||
public BattalionView Battalion
|
||||
{
|
||||
set
|
||||
{
|
||||
battalionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(value.Type);
|
||||
if (battalionImage.texture == null)
|
||||
{
|
||||
battalionImage.color = Color.clear;
|
||||
}
|
||||
public BattalionView Battalion {
|
||||
set {
|
||||
battalionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(
|
||||
value.Type);
|
||||
if (battalionImage.texture == null) { battalionImage.color = Color.clear; }
|
||||
sizeLabel.text = value.Size.ToString();
|
||||
trainingLabel.text = ((int)value.Training).ToString();
|
||||
armamentLabel.text = ((int)value.Armament).ToString();
|
||||
|
||||
+8
-17
@@ -4,10 +4,8 @@ using Net.Eagle0.Eagle.Api;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class CombatUnitRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class CombatUnitRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public TMP_Text heroNameLabel;
|
||||
public RawImage battalionImage;
|
||||
@@ -15,29 +13,22 @@ namespace eagle
|
||||
public TMP_Text trainingLabel;
|
||||
public TMP_Text armamentLabel;
|
||||
|
||||
public HeroView Hero
|
||||
{
|
||||
set
|
||||
{
|
||||
public HeroView Hero {
|
||||
set {
|
||||
professionImage.texture = CommonTextures.Profession(value.Profession);
|
||||
professionImage.color = professionImage.texture == null ? Color.clear : Color.white;
|
||||
heroNameLabel.text = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public BattalionView Battalion
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
public BattalionView Battalion {
|
||||
set {
|
||||
if (value == null) {
|
||||
battalionImage.texture = null;
|
||||
sizeLabel.text = "0";
|
||||
trainingLabel.text = null;
|
||||
armamentLabel.text = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
battalionImage.texture = CommonTextures.BattalionType(value.Type);
|
||||
sizeLabel.text = value.Size.ToString();
|
||||
trainingLabel.text = ((int)value.Training).ToString();
|
||||
|
||||
+39
-43
@@ -5,10 +5,8 @@ using Net.Eagle0.Common;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class CustomUnitRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class CustomUnitRowController : TableRowController {
|
||||
public TMP_Dropdown professionDropdown;
|
||||
public TMP_InputField heroName;
|
||||
public TMP_InputField strength;
|
||||
@@ -29,53 +27,46 @@ namespace eagle
|
||||
public Toggle canStartFire;
|
||||
public Button deleteButton;
|
||||
|
||||
public CommonProfession SelectedProfession
|
||||
{
|
||||
get => professionDropdown.value == 0 ? CommonProfession.NoProfession : (CommonProfession)(professionDropdown.value);
|
||||
public CommonProfession SelectedProfession {
|
||||
get => professionDropdown.value == 0 ? CommonProfession.NoProfession
|
||||
: (CommonProfession)(professionDropdown.value);
|
||||
set => professionDropdown.value = (int)value;
|
||||
}
|
||||
|
||||
public CommonBattalionTypeId SelectedBattalionTypeId
|
||||
{
|
||||
public CommonBattalionTypeId SelectedBattalionTypeId {
|
||||
get => (CommonBattalionTypeId)battalionTypeDropdown.value;
|
||||
set => battalionTypeDropdown.value = (int)value;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
private void Start() {}
|
||||
|
||||
public void DeleteButtonClicked()
|
||||
{
|
||||
public void DeleteButtonClicked() {
|
||||
GetComponentInParent<EventBasedTable>().RemoveRow(this);
|
||||
}
|
||||
|
||||
private List<int> _availableStartingPositions;
|
||||
public List<int> AvailableStartingPositions
|
||||
{
|
||||
public List<int> AvailableStartingPositions {
|
||||
get => _availableStartingPositions;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_availableStartingPositions = value;
|
||||
if (_availableStartingPositions.Count == 0)
|
||||
{
|
||||
startingPosition.options = new List<TMP_Dropdown.OptionData> { new TMP_Dropdown.OptionData("DEF") };
|
||||
}
|
||||
else
|
||||
{
|
||||
startingPosition.options = _availableStartingPositions.Select(i => new TMP_Dropdown.OptionData(i.ToString())).ToList();
|
||||
if (_availableStartingPositions.Count == 0) {
|
||||
startingPosition.options = new List<TMP_Dropdown.OptionData> {
|
||||
new TMP_Dropdown.OptionData("DEF")
|
||||
};
|
||||
} else {
|
||||
startingPosition.options =
|
||||
_availableStartingPositions
|
||||
.Select(i => new TMP_Dropdown.OptionData(i.ToString()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
startingPosition.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public CommonUnit Unit
|
||||
{
|
||||
get
|
||||
{
|
||||
var hero = new CommonHero
|
||||
{
|
||||
public CommonUnit Unit {
|
||||
get {
|
||||
var hero = new CommonHero {
|
||||
Name = heroName.text,
|
||||
Profession = SelectedProfession,
|
||||
Strength = int.Parse(strength.text),
|
||||
@@ -88,30 +79,33 @@ namespace eagle
|
||||
IsVip = isVip.isOn
|
||||
};
|
||||
|
||||
var battalion = SelectedBattalionTypeId == CommonBattalionTypeId.Undead ? null : new CommonBattalion
|
||||
{
|
||||
var battalion = SelectedBattalionTypeId == CommonBattalionTypeId.Undead
|
||||
? null
|
||||
: new CommonBattalion {
|
||||
Type = SelectedBattalionTypeId,
|
||||
Size = int.Parse(sizeLabel.text),
|
||||
Training = double.Parse(trainingLabel.text),
|
||||
Armament = double.Parse(armamentLabel.text)
|
||||
};
|
||||
|
||||
return new CommonUnit
|
||||
{
|
||||
return new CommonUnit {
|
||||
Hero = hero,
|
||||
Battalion = battalion,
|
||||
StartingPositionIndex = _availableStartingPositions != null && _availableStartingPositions.Count > 0
|
||||
? (int?)_availableStartingPositions[startingPosition.value]
|
||||
: (int?)null,
|
||||
StartingPositionIndex =
|
||||
_availableStartingPositions != null &&
|
||||
_availableStartingPositions.Count >
|
||||
0?(int?)_availableStartingPositions[startingPosition.value] :
|
||||
(int?)null,
|
||||
CanFlee = canFlee.isOn,
|
||||
CanArchery = canArchery.isOn,
|
||||
CanStartFire = canStartFire.isOn
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
set {
|
||||
heroName.text = value.Hero.Name;
|
||||
professionDropdown.value = value.Hero.Profession == CommonProfession.NoProfession ? 0 : (int)value.Hero.Profession;
|
||||
professionDropdown.value = value.Hero.Profession == CommonProfession.NoProfession
|
||||
? 0
|
||||
: (int)value.Hero.Profession;
|
||||
strength.text = value.Hero.Strength.ToString();
|
||||
agility.text = value.Hero.Agility.ToString();
|
||||
constitution.text = value.Hero.Constitution.ToString();
|
||||
@@ -125,8 +119,10 @@ namespace eagle
|
||||
trainingLabel.text = value.Battalion.Training.ToString();
|
||||
armamentLabel.text = value.Battalion.Armament.ToString();
|
||||
|
||||
startingPosition.value = (value.StartingPositionIndex.HasValue && _availableStartingPositions != null)
|
||||
? _availableStartingPositions.IndexOf(value.StartingPositionIndex.Value)
|
||||
startingPosition.value = (value.StartingPositionIndex.HasValue &&
|
||||
_availableStartingPositions != null)
|
||||
? _availableStartingPositions.IndexOf(
|
||||
value.StartingPositionIndex.Value)
|
||||
: 0;
|
||||
canFlee.isOn = value.CanFlee;
|
||||
}
|
||||
|
||||
+32
-45
@@ -8,12 +8,13 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class DominionTableRowController : TableRowController, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
public class DominionTableRowController : TableRowController,
|
||||
IPointerEnterHandler,
|
||||
IPointerExitHandler,
|
||||
IPointerClickHandler {
|
||||
public TMP_Text provinceName;
|
||||
public TMP_Text ruler;
|
||||
public TMP_Text support;
|
||||
@@ -36,38 +37,28 @@ namespace eagle
|
||||
|
||||
private ProvinceId ProvinceId;
|
||||
|
||||
private void SetDevastatedValue(TMP_Text textField, double baseValue, double devastation)
|
||||
{
|
||||
if (devastation == 0.0)
|
||||
{
|
||||
private void SetDevastatedValue(TMP_Text textField, double baseValue, double devastation) {
|
||||
if (devastation == 0.0) {
|
||||
textField.color = Color.black;
|
||||
textField.text = baseValue.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
textField.color = Color.red;
|
||||
var devastatedValue = Math.Max(0.0, baseValue - devastation);
|
||||
textField.text = devastatedValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(ProvinceId provinceId, GameModel model, bool isSelected, bool hasCommands)
|
||||
{
|
||||
public void Set(ProvinceId provinceId, GameModel model, bool isSelected, bool hasCommands) {
|
||||
ProvinceId = provinceId;
|
||||
|
||||
var province = model.Provinces[provinceId];
|
||||
|
||||
provinceName.text = province.Name;
|
||||
if (isSelected)
|
||||
{
|
||||
if (isSelected) {
|
||||
provinceName.color = Color.magenta;
|
||||
}
|
||||
else if (hasCommands)
|
||||
{
|
||||
} else if (hasCommands) {
|
||||
provinceName.color = Color.blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
provinceName.color = Color.black;
|
||||
}
|
||||
|
||||
@@ -77,9 +68,18 @@ namespace eagle
|
||||
battalionCount.text = province.FullInfo.Battalions.Count.ToString();
|
||||
troopCount.text = province.FullInfo.Battalions.Sum(x => x.Size).ToString();
|
||||
|
||||
SetDevastatedValue(economy, province.FullInfo.Economy, province.FullInfo.EconomyDevastation);
|
||||
SetDevastatedValue(agriculture, province.FullInfo.Agriculture, province.FullInfo.AgricultureDevastation);
|
||||
SetDevastatedValue(infrastructure, province.FullInfo.Infrastructure, province.FullInfo.InfrastructureDevastation);
|
||||
SetDevastatedValue(
|
||||
economy,
|
||||
province.FullInfo.Economy,
|
||||
province.FullInfo.EconomyDevastation);
|
||||
SetDevastatedValue(
|
||||
agriculture,
|
||||
province.FullInfo.Agriculture,
|
||||
province.FullInfo.AgricultureDevastation);
|
||||
SetDevastatedValue(
|
||||
infrastructure,
|
||||
province.FullInfo.Infrastructure,
|
||||
province.FullInfo.InfrastructureDevastation);
|
||||
|
||||
gold.text = province.FullInfo.Gold.ToString();
|
||||
food.text = province.FullInfo.Food.ToString();
|
||||
@@ -93,10 +93,8 @@ namespace eagle
|
||||
festival.gameObject.SetActive(false);
|
||||
flood.gameObject.SetActive(false);
|
||||
|
||||
foreach (var pe in province.KnownEvents)
|
||||
{
|
||||
switch (pe.SealedValueCase)
|
||||
{
|
||||
foreach (var pe in province.KnownEvents) {
|
||||
switch (pe.SealedValueCase) {
|
||||
case Net.Eagle0.Eagle.Common.ProvinceEvent.SealedValueOneofCase.BeastsEvent:
|
||||
beasts.gameObject.SetActive(true);
|
||||
break;
|
||||
@@ -125,35 +123,24 @@ namespace eagle
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
void Update() {}
|
||||
|
||||
}
|
||||
public void Clicked() {}
|
||||
|
||||
public void Clicked()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
ShadeOn();
|
||||
GetComponentInParent<DominionPanelController>().RowHovered(ProvinceId);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
ShadeOff();
|
||||
GetComponentInParent<DominionPanelController>().RowUnhovered();
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerClick(PointerEventData eventData) {
|
||||
GetComponentInParent<DominionPanelController>().RowClicked(ProvinceId);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-21
@@ -5,10 +5,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class ExchangedHeroRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class ExchangedHeroRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public TMP_Text heroNameLabel;
|
||||
public TMP_Text strLabel;
|
||||
@@ -23,33 +21,28 @@ namespace eagle
|
||||
public RawImage prisonerImage;
|
||||
public TMP_Text lastFactionLabel;
|
||||
|
||||
public void SetHostage(HeroView hero, string factionName)
|
||||
{
|
||||
public void SetHostage(HeroView hero, string factionName) {
|
||||
SetHero(hero, factionName);
|
||||
prisonerImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetPrisoner(HeroView hero, string factionName)
|
||||
{
|
||||
public void SetPrisoner(HeroView hero, string factionName) {
|
||||
SetHero(hero, factionName);
|
||||
prisonerImage.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetHero(HeroView hero, string factionName)
|
||||
{
|
||||
professionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(hero.Profession);
|
||||
if (professionImage.texture == null)
|
||||
{
|
||||
public void SetHero(HeroView hero, string factionName) {
|
||||
professionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
hero.Profession);
|
||||
if (professionImage.texture == null) {
|
||||
professionImage.color = Color.clear;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
professionImage.color = Color.white;
|
||||
}
|
||||
heroNameLabel.text = hero.Name;
|
||||
|
||||
if (hero.Strength > 0)
|
||||
{
|
||||
if (hero.Strength > 0) {
|
||||
strLabel.text = hero.Strength.ToString();
|
||||
agiLabel.text = hero.Agility.ToString();
|
||||
wisLabel.text = hero.Wisdom.ToString();
|
||||
@@ -58,9 +51,7 @@ namespace eagle
|
||||
|
||||
archeryImage.gameObject.SetActive(hero.ArcheryCapable);
|
||||
fireImage.gameObject.SetActive(hero.StartFireCapable);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
strLabel.text = "";
|
||||
agiLabel.text = "";
|
||||
wisLabel.text = "";
|
||||
|
||||
+2
-6
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ExtraTroopsRowController : TableRowController
|
||||
{
|
||||
public class ExtraTroopsRowController : TableRowController {
|
||||
public TMP_Text sizeField;
|
||||
public TMP_Text trainingField;
|
||||
public TMP_Text armamentField;
|
||||
@@ -14,8 +13,5 @@ public class ExtraTroopsRowController : TableRowController
|
||||
public double Armament { set => armamentField.text = ((int)value).ToString(); }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
|
||||
+11
-27
@@ -3,12 +3,10 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
namespace eagle {
|
||||
using FactionId = System.Int32;
|
||||
|
||||
public class FactionTableRow : TableRowController, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public class FactionTableRow : TableRowController, IPointerEnterHandler, IPointerExitHandler {
|
||||
public TMP_Text factionLabel;
|
||||
public TMP_Text provinceCountLabel;
|
||||
public TMP_Text treatyStatusLabel;
|
||||
@@ -18,43 +16,29 @@ namespace eagle
|
||||
|
||||
public FactionId FactionId;
|
||||
|
||||
public string Faction
|
||||
{
|
||||
set => factionLabel.text = value;
|
||||
}
|
||||
public string Faction { set => factionLabel.text = value; }
|
||||
|
||||
public Color FactionColor
|
||||
{
|
||||
public Color FactionColor {
|
||||
get => _factionColor;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_factionColor = value;
|
||||
colorBox.color = value;
|
||||
provinceCountLabel.outlineColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ProvinceCount
|
||||
{
|
||||
set => provinceCountLabel.text = value.ToString();
|
||||
public int ProvinceCount { set => provinceCountLabel.text = value.ToString(); }
|
||||
|
||||
public string TreatyStatus {
|
||||
set { treatyStatusLabel.text = value; }
|
||||
}
|
||||
|
||||
public string TreatyStatus
|
||||
{
|
||||
set
|
||||
{
|
||||
treatyStatusLabel.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
ShadeOn();
|
||||
GetComponentInParent<FocusInfoPanelController>().FactionRowHovered(FactionId);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
ShadeOff();
|
||||
GetComponentInParent<FocusInfoPanelController>().FactionRowUnhovered();
|
||||
}
|
||||
|
||||
+17
-21
@@ -4,10 +4,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class HeroRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class HeroRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public TMP_Text heroNameLabel;
|
||||
public TMP_Text strengthLabel;
|
||||
@@ -25,24 +23,20 @@ namespace eagle
|
||||
public RawImage archeryImage;
|
||||
public RawImage fireImage;
|
||||
|
||||
public HeroView Hero
|
||||
{
|
||||
set
|
||||
{
|
||||
professionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(value.Profession);
|
||||
if (professionImage.texture == null)
|
||||
{
|
||||
public HeroView Hero {
|
||||
set {
|
||||
professionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
value.Profession);
|
||||
if (professionImage.texture == null) {
|
||||
professionImage.color = Color.clear;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
professionImage.color = Color.white;
|
||||
}
|
||||
heroNameLabel.text = value.Name;
|
||||
|
||||
// not ideal -- this is just so we don't show 0s for scouted heroes
|
||||
if (value.Strength != 0)
|
||||
{
|
||||
if (value.Strength != 0) {
|
||||
strengthLabel.text = value.Strength.ToString();
|
||||
strengthXpLabel.text = $"({value.StrengthXp})";
|
||||
agilityLabel.text = value.Agility.ToString();
|
||||
@@ -51,15 +45,17 @@ namespace eagle
|
||||
wisdomXpLabel.text = $"({value.WisdomXp})";
|
||||
charismaLabel.text = value.Charisma.ToString();
|
||||
charismaXpLabel.text = $"({value.CharismaXp})";
|
||||
vigorLabel.text = value.Vigor == null ? null : GUIUtils.ConditionString(value.Vigor) + "/" + (value.Constitution.ToString());
|
||||
vigorLabel.text = value.Vigor == null
|
||||
? null
|
||||
: GUIUtils.ConditionString(value.Vigor) + "/" +
|
||||
(value.Constitution.ToString());
|
||||
constitutionXpLabel.text = $"({value.ConstitutionXp})";
|
||||
loyaltyLabel.text = value.Loyalty == null ? "—" : GUIUtils.ConditionString(value.Loyalty);
|
||||
loyaltyLabel.text =
|
||||
value.Loyalty == null ? "—" : GUIUtils.ConditionString(value.Loyalty);
|
||||
|
||||
archeryImage.gameObject.SetActive(value.ArcheryCapable);
|
||||
fireImage.gameObject.SetActive(value.StartFireCapable);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
strengthLabel.text = "?";
|
||||
strengthXpLabel.text = "?";
|
||||
agilityLabel.text = "?";
|
||||
|
||||
+6
-20
@@ -1,33 +1,19 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class IncomingArmyTableRow : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class IncomingArmyTableRow : TableRowController {
|
||||
public TMP_Text factionLabel;
|
||||
public TMP_Text heroCountLabel;
|
||||
public TMP_Text troopCountLabel;
|
||||
public TMP_Text originLabel;
|
||||
|
||||
public string Faction
|
||||
{
|
||||
set => factionLabel.text = value;
|
||||
}
|
||||
public string Faction { set => factionLabel.text = value; }
|
||||
|
||||
public int HeroCount
|
||||
{
|
||||
set => heroCountLabel.text = value.ToString();
|
||||
}
|
||||
public int HeroCount { set => heroCountLabel.text = value.ToString(); }
|
||||
|
||||
public int TroopCount
|
||||
{
|
||||
set => troopCountLabel.text = value.ToString();
|
||||
}
|
||||
public int TroopCount { set => troopCountLabel.text = value.ToString(); }
|
||||
|
||||
public string Origin
|
||||
{
|
||||
set => originLabel.text = value;
|
||||
}
|
||||
public string Origin { set => originLabel.text = value; }
|
||||
}
|
||||
}
|
||||
+19
-40
@@ -2,10 +2,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class MovingArmyTableRow : TableRowController, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
namespace eagle {
|
||||
public class MovingArmyTableRow : TableRowController,
|
||||
IPointerEnterHandler,
|
||||
IPointerExitHandler {
|
||||
public GameObject factionRow;
|
||||
public TMP_Text factionLabel;
|
||||
public GameObject heroesTroopsRow;
|
||||
@@ -17,20 +17,16 @@ namespace eagle
|
||||
public TMP_Text originLabel;
|
||||
public TMP_Text destinationLabel;
|
||||
|
||||
public string Faction
|
||||
{
|
||||
set
|
||||
{
|
||||
public string Faction {
|
||||
set {
|
||||
factionLabel.text = value;
|
||||
factionRow.SetActive(!string.IsNullOrEmpty(value));
|
||||
}
|
||||
}
|
||||
|
||||
private int _heroCount;
|
||||
public int HeroCount
|
||||
{
|
||||
set
|
||||
{
|
||||
public int HeroCount {
|
||||
set {
|
||||
_heroCount = value;
|
||||
heroCountLabel.text = _heroCount.ToString();
|
||||
heroesTroopsRow.SetActive(_heroCount != 0 || _troopCount != 0);
|
||||
@@ -38,10 +34,8 @@ namespace eagle
|
||||
}
|
||||
|
||||
private int _troopCount;
|
||||
public int TroopCount
|
||||
{
|
||||
set
|
||||
{
|
||||
public int TroopCount {
|
||||
set {
|
||||
_troopCount = value;
|
||||
troopCountLabel.text = value.ToString();
|
||||
heroesTroopsRow.SetActive(_heroCount != 0 || _troopCount != 0);
|
||||
@@ -49,10 +43,8 @@ namespace eagle
|
||||
}
|
||||
|
||||
private int _food = 0;
|
||||
public int Food
|
||||
{
|
||||
set
|
||||
{
|
||||
public int Food {
|
||||
set {
|
||||
_food = value;
|
||||
foodLabel.text = _food.ToString();
|
||||
suppliesRow.SetActive(_food != 0 || _gold != 0);
|
||||
@@ -60,39 +52,26 @@ namespace eagle
|
||||
}
|
||||
|
||||
private int _gold = 0;
|
||||
public int Gold
|
||||
{
|
||||
set
|
||||
{
|
||||
public int Gold {
|
||||
set {
|
||||
_gold = value;
|
||||
goldLabel.text = _gold.ToString();
|
||||
suppliesRow.SetActive(_food != 0 || _gold != 0);
|
||||
}
|
||||
}
|
||||
|
||||
public string Origin
|
||||
{
|
||||
set => originLabel.text = value;
|
||||
}
|
||||
public string Origin { set => originLabel.text = value; }
|
||||
|
||||
public string Destination
|
||||
{
|
||||
set => destinationLabel.text = value;
|
||||
}
|
||||
public string Destination { set => destinationLabel.text = value; }
|
||||
|
||||
public Color DestinationColor
|
||||
{
|
||||
set => destinationLabel.color = value;
|
||||
}
|
||||
public Color DestinationColor { set => destinationLabel.color = value; }
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerEnter(PointerEventData eventData) {
|
||||
GetComponentInParent<FocusInfoPanelController>().MovingArmyRowHovered(this);
|
||||
ShadeOn();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
GetComponentInParent<FocusInfoPanelController>().FactionRowUnhovered();
|
||||
ShadeOff();
|
||||
}
|
||||
|
||||
+8
-21
@@ -3,10 +3,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class OrganizeTroopsComponentRow : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class OrganizeTroopsComponentRow : MonoBehaviour {
|
||||
public TMP_Text sizeField;
|
||||
public TMP_Text armamentField;
|
||||
public TMP_Text trainingField;
|
||||
@@ -15,28 +13,21 @@ namespace eagle
|
||||
public Image armamentBackground;
|
||||
public Image trainingBackground;
|
||||
|
||||
public BattalionComponent BattalionComponent
|
||||
{
|
||||
set
|
||||
{
|
||||
public BattalionComponent BattalionComponent {
|
||||
set {
|
||||
armamentField.text = Math.Floor(value.armament).ToString();
|
||||
trainingField.text = Math.Floor(value.training).ToString();
|
||||
sizeField.text = value.count.ToString();
|
||||
|
||||
Color color = Color.black;
|
||||
switch (value.source)
|
||||
{
|
||||
switch (value.source) {
|
||||
case BattalionComponent.ComponentSource.originalTroops:
|
||||
color = Color.black;
|
||||
break;
|
||||
|
||||
case BattalionComponent.ComponentSource.mergedTroops:
|
||||
color = Color.blue;
|
||||
break;
|
||||
case BattalionComponent.ComponentSource.mergedTroops: color = Color.blue; break;
|
||||
|
||||
case BattalionComponent.ComponentSource.newTroops:
|
||||
color = Color.green;
|
||||
break;
|
||||
case BattalionComponent.ComponentSource.newTroops: color = Color.green; break;
|
||||
}
|
||||
|
||||
color.a = 0.25f;
|
||||
@@ -47,10 +38,6 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Start() {}
|
||||
}
|
||||
}
|
||||
+13
-40
@@ -3,10 +3,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class OrganizeTroopsResultRow : MonoBehaviour
|
||||
{
|
||||
namespace eagle {
|
||||
public class OrganizeTroopsResultRow : MonoBehaviour {
|
||||
public RawImage battalionImage;
|
||||
public TMP_Text priceLabel;
|
||||
public TMP_Text newTrainingLabel;
|
||||
@@ -16,50 +14,25 @@ namespace eagle
|
||||
public TMP_Text totalCostLabel;
|
||||
public TMP_Text battalionNameLabel;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
private void Start() {}
|
||||
|
||||
public Texture BattalionImage
|
||||
{
|
||||
set => battalionImage.texture = value;
|
||||
}
|
||||
public Texture BattalionImage { set => battalionImage.texture = value; }
|
||||
|
||||
public double Price
|
||||
{
|
||||
set => priceLabel.text = value.ToString("0.##");
|
||||
}
|
||||
public double Price { set => priceLabel.text = value.ToString("0.##"); }
|
||||
|
||||
public double Training
|
||||
{
|
||||
set => newTrainingLabel.text = Math.Floor(value).ToString();
|
||||
}
|
||||
public double Training { set => newTrainingLabel.text = Math.Floor(value).ToString(); }
|
||||
|
||||
public double Armament
|
||||
{
|
||||
set => newArmamentLabel.text = Math.Floor(value).ToString();
|
||||
}
|
||||
public double Armament { set => newArmamentLabel.text = Math.Floor(value).ToString(); }
|
||||
|
||||
public int Size
|
||||
{
|
||||
set => newSizeLabel.text = value.ToString();
|
||||
}
|
||||
public int Size { set => newSizeLabel.text = value.ToString(); }
|
||||
|
||||
public int Capacity
|
||||
{
|
||||
set => sizeCapLabel.text = value.ToString();
|
||||
}
|
||||
public int Capacity { set => sizeCapLabel.text = value.ToString(); }
|
||||
|
||||
public string Name
|
||||
{
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
public string Name {
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
battalionNameLabel.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
battalionNameLabel.gameObject.SetActive(true);
|
||||
battalionNameLabel.text = value;
|
||||
}
|
||||
|
||||
+31
-63
@@ -4,15 +4,14 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class OrganizeTroopsTableRow : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class OrganizeTroopsTableRow : TableRowController {
|
||||
public LayoutElement layoutElement;
|
||||
public OrganizeTroopsResultRow resultRow;
|
||||
public OrganizeTroopsComponentRow componentRowPrefab;
|
||||
public Transform componentsLayoutTransform;
|
||||
private List<OrganizeTroopsComponentRow> existingComponents = new List<OrganizeTroopsComponentRow>();
|
||||
private List<OrganizeTroopsComponentRow> existingComponents =
|
||||
new List<OrganizeTroopsComponentRow>();
|
||||
|
||||
public Toggle disclosureTriangle;
|
||||
|
||||
@@ -29,28 +28,23 @@ namespace eagle
|
||||
private BattalionDisplayInfo _displayInfo;
|
||||
|
||||
private bool _canAugment = true;
|
||||
public Boolean CanAugment
|
||||
{
|
||||
public Boolean CanAugment {
|
||||
get => _canAugment;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_canAugment = value;
|
||||
SetButtons();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetButtons()
|
||||
{
|
||||
private void SetButtons() {
|
||||
AllowPlus = BattalionInfo.Count < BattalionInfo.Capacity && CanAugment;
|
||||
AllowMax = BattalionInfo.Count < BattalionInfo.Capacity && CanAugment;
|
||||
AllowMinus = BattalionInfo.Count > 0;
|
||||
}
|
||||
|
||||
public BattalionDisplayInfo BattalionInfo
|
||||
{
|
||||
public BattalionDisplayInfo BattalionInfo {
|
||||
get => _displayInfo;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_displayInfo = value;
|
||||
|
||||
resultRow.BattalionImage = value.Image;
|
||||
@@ -71,84 +65,58 @@ namespace eagle
|
||||
}
|
||||
|
||||
private List<BattalionComponent> _components = new List<BattalionComponent>();
|
||||
public List<BattalionComponent> Components
|
||||
{
|
||||
get => _components;
|
||||
}
|
||||
public List<BattalionComponent> Components { get => _components; }
|
||||
|
||||
private void DrawComponents()
|
||||
{
|
||||
private void DrawComponents() {
|
||||
existingComponents.ForEach(t => Destroy(t.gameObject));
|
||||
existingComponents.Clear();
|
||||
|
||||
var resultHeight = resultRow.GetComponent<LayoutElement>().minHeight;
|
||||
|
||||
if (disclosureTriangle.isOn)
|
||||
{
|
||||
if (disclosureTriangle.isOn) {
|
||||
existingComponents = Components
|
||||
.Select(comp =>
|
||||
{
|
||||
var cr = Instantiate(componentRowPrefab, componentsLayoutTransform);
|
||||
.Select(comp => {
|
||||
var cr = Instantiate(
|
||||
componentRowPrefab,
|
||||
componentsLayoutTransform);
|
||||
cr.BattalionComponent = comp;
|
||||
return cr;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
layoutElement.minHeight = resultHeight + existingComponents.Select(c => c.gameObject.GetComponent<LayoutElement>().minHeight).Sum();
|
||||
}
|
||||
else
|
||||
{
|
||||
layoutElement.minHeight =
|
||||
resultHeight +
|
||||
existingComponents
|
||||
.Select(c => c.gameObject.GetComponent<LayoutElement>().minHeight)
|
||||
.Sum();
|
||||
} else {
|
||||
layoutElement.minHeight = resultHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
private void Start() {
|
||||
disclosureTriangle.isOn = BattalionInfo != null && BattalionInfo.Open;
|
||||
}
|
||||
|
||||
|
||||
public void DisclosureTriangleToggled(bool newValue)
|
||||
{
|
||||
public void DisclosureTriangleToggled(bool newValue) {
|
||||
BattalionInfo.Open = newValue;
|
||||
|
||||
DrawComponents();
|
||||
}
|
||||
|
||||
public bool AllowPlus
|
||||
{
|
||||
set => plusButton.interactable = value;
|
||||
}
|
||||
public bool AllowPlus { set => plusButton.interactable = value; }
|
||||
|
||||
public bool AllowMinus
|
||||
{
|
||||
set => minusButton.interactable = value;
|
||||
}
|
||||
public bool AllowMinus { set => minusButton.interactable = value; }
|
||||
|
||||
public bool AllowMax
|
||||
{
|
||||
set => maxButton.interactable = value;
|
||||
}
|
||||
public bool AllowMax { set => maxButton.interactable = value; }
|
||||
|
||||
public void PlusButtonClicked()
|
||||
{
|
||||
PlusButtonClickedCallback();
|
||||
}
|
||||
public void PlusButtonClicked() { PlusButtonClickedCallback(); }
|
||||
|
||||
public void MinusButtonClicked()
|
||||
{
|
||||
MinusButtonClickedCallback();
|
||||
}
|
||||
public void MinusButtonClicked() { MinusButtonClickedCallback(); }
|
||||
|
||||
public void MaxButtonClicked()
|
||||
{
|
||||
MaxButtonClickedCallback();
|
||||
}
|
||||
public void MaxButtonClicked() { MaxButtonClickedCallback(); }
|
||||
|
||||
public void DismissButtonClicked()
|
||||
{
|
||||
DismissButtonClickedCallback();
|
||||
}
|
||||
public void DismissButtonClicked() { DismissButtonClickedCallback(); }
|
||||
}
|
||||
}
|
||||
+37
-52
@@ -6,10 +6,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class SelectedUnitRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class SelectedUnitRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public RawImage archeryImage;
|
||||
public RawImage fireImage;
|
||||
@@ -23,22 +21,18 @@ namespace eagle
|
||||
public RawImage armamentImage;
|
||||
public TMP_Text battalionNameLabel;
|
||||
|
||||
public HeroView Hero
|
||||
{
|
||||
set
|
||||
{
|
||||
|
||||
public HeroView Hero {
|
||||
set {
|
||||
archeryImage.gameObject.SetActive(false);
|
||||
fireImage.gameObject.SetActive(false);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
if (value == null) {
|
||||
heroNameLabel.text = "None";
|
||||
heroNameLabel.color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
professionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(value.Profession);
|
||||
} else {
|
||||
professionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
value.Profession);
|
||||
heroNameLabel.text = value.Name;
|
||||
archeryImage.gameObject.SetActive(value.ArcheryCapable);
|
||||
fireImage.gameObject.SetActive(value.StartFireCapable);
|
||||
@@ -47,10 +41,8 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public UnityEngine.Events.UnityAction HeroClickDetector
|
||||
{
|
||||
set
|
||||
{
|
||||
public UnityEngine.Events.UnityAction HeroClickDetector {
|
||||
set {
|
||||
heroNameLabel.GetComponent<TableRowClickDetector>().onClick.AddListener(value);
|
||||
heroNameLabel.GetComponent<TableRowClickDetector>().selectable = true;
|
||||
professionImage.GetComponent<TableRowClickDetector>().onClick.AddListener(value);
|
||||
@@ -62,27 +54,19 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public bool Appropriate
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
public bool Appropriate {
|
||||
set {
|
||||
if (value) {
|
||||
heroNameLabel.color = Color.black;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
heroNameLabel.color = Color.red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BattalionView Battalion
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
public BattalionView Battalion {
|
||||
set {
|
||||
if (value == null) {
|
||||
battalionImage.color = Color.clear;
|
||||
trainImage.color = Color.clear;
|
||||
armamentImage.color = Color.clear;
|
||||
@@ -90,14 +74,11 @@ namespace eagle
|
||||
trainingLabel.text = "";
|
||||
armamentLabel.text = "";
|
||||
battalionNameLabel.text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
battalionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(value.Type);
|
||||
if (battalionImage.texture == null)
|
||||
{
|
||||
battalionImage.color = Color.clear;
|
||||
}
|
||||
} else {
|
||||
battalionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().BattalionType(
|
||||
value.Type);
|
||||
if (battalionImage.texture == null) { battalionImage.color = Color.clear; }
|
||||
sizeLabel.text = value.Size.ToString();
|
||||
trainingLabel.text = ((int)value.Training).ToString();
|
||||
armamentLabel.text = ((int)value.Armament).ToString();
|
||||
@@ -106,21 +87,25 @@ namespace eagle
|
||||
}
|
||||
}
|
||||
|
||||
public UnityEngine.Events.UnityAction BattalionClickDetector
|
||||
{
|
||||
set
|
||||
{
|
||||
battalionImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
public UnityEngine.Events.UnityAction BattalionClickDetector {
|
||||
set {
|
||||
battalionImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
battalionImage.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
sizeLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
sizeLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
sizeLabel.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
trainingLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
trainingLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
trainingLabel.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
armamentLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
armamentLabel.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
armamentLabel.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
trainImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
trainImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
trainImage.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
armamentImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(value);
|
||||
armamentImage.GetComponentInChildren<TableRowClickDetector>().onClick.AddListener(
|
||||
value);
|
||||
armamentImage.GetComponentInChildren<TableRowClickDetector>().selectable = true;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-41
@@ -2,79 +2,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TableRowController : MonoBehaviour
|
||||
{
|
||||
public class TableRowController : MonoBehaviour {
|
||||
public TableRowClickDetector ClickDetector => GetComponent<TableRowClickDetector>();
|
||||
|
||||
public EagleCommonTextures CommonTextures => gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
public EagleCommonTextures CommonTextures =>
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>();
|
||||
|
||||
private bool _selected = false;
|
||||
public bool Selected
|
||||
{
|
||||
public bool Selected {
|
||||
get => _selected;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_selected = value;
|
||||
ColorRow();
|
||||
}
|
||||
}
|
||||
|
||||
private Color _backgroundColor = Color.white;
|
||||
virtual public Color BackgroundColor
|
||||
{
|
||||
virtual public Color BackgroundColor {
|
||||
get => _backgroundColor;
|
||||
set
|
||||
{
|
||||
set {
|
||||
_backgroundColor = value;
|
||||
ColorRow();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Selectable
|
||||
{
|
||||
public bool Selectable {
|
||||
get => ClickDetector != null && ClickDetector.selectable;
|
||||
set
|
||||
{
|
||||
set {
|
||||
if (ClickDetector != null) ClickDetector.selectable = value;
|
||||
if (!value) Selected = false;
|
||||
ColorRow();
|
||||
}
|
||||
}
|
||||
|
||||
public bool RightSelectable
|
||||
{
|
||||
public bool RightSelectable {
|
||||
get => ClickDetector != null && ClickDetector.rightSelectable;
|
||||
set
|
||||
{
|
||||
set {
|
||||
if (ClickDetector != null) ClickDetector.rightSelectable = value;
|
||||
ColorRow();
|
||||
}
|
||||
}
|
||||
|
||||
private Color _textColor = Color.black;
|
||||
public Color TextColor
|
||||
{
|
||||
set
|
||||
{
|
||||
public Color TextColor {
|
||||
set {
|
||||
_textColor = value;
|
||||
foreach (var text in gameObject.GetComponentsInChildren<TMP_Text>())
|
||||
{
|
||||
foreach (var text in gameObject.GetComponentsInChildren<TMP_Text>()) {
|
||||
text.color = _textColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ColorRow()
|
||||
{
|
||||
if (ClickDetector != null)
|
||||
{
|
||||
public void ColorRow() {
|
||||
if (ClickDetector != null) {
|
||||
var newColor = Color.black;
|
||||
if (Selected)
|
||||
{
|
||||
if (Selected) {
|
||||
newColor = Color.blue;
|
||||
}
|
||||
else if (!Selectable && !RightSelectable)
|
||||
{
|
||||
} else if (!Selectable && !RightSelectable) {
|
||||
newColor = Color.gray;
|
||||
}
|
||||
|
||||
@@ -83,14 +67,13 @@ public class TableRowController : MonoBehaviour
|
||||
gameObject.GetComponent<Image>().color = BackgroundColor;
|
||||
}
|
||||
|
||||
public void ShadeOn()
|
||||
{
|
||||
var shadedBackground = new Color(BackgroundColor.r - 0.25f, BackgroundColor.g - 0.25f, BackgroundColor.b + 0.25f);
|
||||
public void ShadeOn() {
|
||||
var shadedBackground = new Color(
|
||||
BackgroundColor.r - 0.25f,
|
||||
BackgroundColor.g - 0.25f,
|
||||
BackgroundColor.b + 0.25f);
|
||||
gameObject.GetComponent<Image>().color = shadedBackground;
|
||||
}
|
||||
|
||||
public void ShadeOff()
|
||||
{
|
||||
gameObject.GetComponent<Image>().color = BackgroundColor;
|
||||
}
|
||||
public void ShadeOff() { gameObject.GetComponent<Image>().color = BackgroundColor; }
|
||||
}
|
||||
|
||||
+14
-22
@@ -4,10 +4,8 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class UnaffiliatedHeroRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class UnaffiliatedHeroRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public TMP_Text heroNameLabel;
|
||||
public TMP_Text questLabel;
|
||||
@@ -20,35 +18,31 @@ namespace eagle
|
||||
public RawImage archeryImage;
|
||||
public RawImage fireImage;
|
||||
|
||||
public void SetUnaffiliatedHero(UnaffiliatedHeroBasics uh, GameModel model)
|
||||
{
|
||||
professionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(uh.Profession);
|
||||
if (professionImage.texture == null)
|
||||
{
|
||||
public void SetUnaffiliatedHero(UnaffiliatedHeroBasics uh, GameModel model) {
|
||||
professionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
uh.Profession);
|
||||
if (professionImage.texture == null) {
|
||||
professionImage.color = Color.clear;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
professionImage.color = Color.white;
|
||||
}
|
||||
heroNameLabel.text = uh.Name;
|
||||
|
||||
switch (uh.RecruitmentInfo.Status)
|
||||
{
|
||||
switch (uh.RecruitmentInfo.Status) {
|
||||
case Net.Eagle0.Eagle.Common.RecruitmentStatus.HasQuest:
|
||||
questLabel.text = DisplayNames.ShortQuestString(uh.RecruitmentInfo.Quest, model);
|
||||
questLabel.text =
|
||||
DisplayNames.ShortQuestString(uh.RecruitmentInfo.Quest, model);
|
||||
break;
|
||||
default:
|
||||
questLabel.text = DisplayNames.ShortRecruitmentStatusString(uh.RecruitmentInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
if (model.Heroes.ContainsKey(uh.HeroId))
|
||||
{
|
||||
if (model.Heroes.ContainsKey(uh.HeroId)) {
|
||||
var hero = model.Heroes[uh.HeroId];
|
||||
|
||||
if (hero.Strength > 0)
|
||||
{
|
||||
if (hero.Strength > 0) {
|
||||
strLabel.text = hero.Strength.ToString();
|
||||
agiLabel.text = hero.Agility.ToString();
|
||||
wisLabel.text = hero.Wisdom.ToString();
|
||||
@@ -57,9 +51,7 @@ namespace eagle
|
||||
|
||||
archeryImage.gameObject.SetActive(hero.ArcheryCapable);
|
||||
fireImage.gameObject.SetActive(hero.StartFireCapable);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
strLabel.text = "";
|
||||
agiLabel.text = "";
|
||||
wisLabel.text = "";
|
||||
|
||||
+7
-9
@@ -4,20 +4,18 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace eagle
|
||||
{
|
||||
public class UnitSelectorHeroRowController : TableRowController
|
||||
{
|
||||
namespace eagle {
|
||||
public class UnitSelectorHeroRowController : TableRowController {
|
||||
public RawImage professionImage;
|
||||
public RawImage archeryImage;
|
||||
public RawImage fireImage;
|
||||
public TMP_Text heroNameLabel;
|
||||
|
||||
public HeroView Hero
|
||||
{
|
||||
set
|
||||
{
|
||||
professionImage.texture = gameObject.GetComponentInParent<EagleCommonTextures>().Profession(value.Profession);
|
||||
public HeroView Hero {
|
||||
set {
|
||||
professionImage.texture =
|
||||
gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
|
||||
value.Profession);
|
||||
heroNameLabel.text = value.Name;
|
||||
archeryImage.gameObject.SetActive(value.ArcheryCapable);
|
||||
fireImage.gameObject.SetActive(value.StartFireCapable);
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TextureList : MonoBehaviour
|
||||
{
|
||||
public class TextureList : MonoBehaviour {
|
||||
public List<Texture> textures;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
void Start() {}
|
||||
}
|
||||
|
||||
@@ -14,31 +14,35 @@ using Grpc.Net.Client;
|
||||
using Grpc.Net.Client.Web;
|
||||
using System.Net.Http;
|
||||
|
||||
public class EagleConnection : IDisposable
|
||||
{
|
||||
public class EagleConnection : IDisposable {
|
||||
private static bool loggerSet = false;
|
||||
|
||||
public readonly string PlayerName;
|
||||
public readonly string Url;
|
||||
public readonly Metadata Credentials;
|
||||
|
||||
public static CancellationToken EagleCancellationToken => ConnectionKiller.EagleCancellationToken;
|
||||
public static CancellationToken ShardokCancellationToken => ConnectionKiller.ShardokCancellationToken;
|
||||
public static CancellationToken EagleCancellationToken =>
|
||||
ConnectionKiller.EagleCancellationToken;
|
||||
public static CancellationToken ShardokCancellationToken =>
|
||||
ConnectionKiller.ShardokCancellationToken;
|
||||
|
||||
public Eagle.EagleClient EagleGrpcClient { get; private set; }
|
||||
public ShardokInternalInterface.ShardokInternalInterfaceClient ShardokInternalInterfaceGrpcClient { get; private set; }
|
||||
public ShardokInternalInterface
|
||||
.ShardokInternalInterfaceClient ShardokInternalInterfaceGrpcClient {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private readonly SslCredentials sslCreds = new SslCredentials();
|
||||
private Action<GamesReply, StatusCode> repeatedCallback;
|
||||
private AsyncServerStreamingCall<GamesReply> streamingCall;
|
||||
|
||||
private CallInvoker MakeInvoker(string playerName, string password, string url)
|
||||
{
|
||||
private CallInvoker MakeInvoker(string playerName, string password, string url) {
|
||||
var authInterceptor = new AuthInterceptor(playerName, password);
|
||||
|
||||
GrpcWebMode mode = GrpcWebMode.GrpcWebText;
|
||||
var channel = GrpcChannel.ForAddress("https://" + url, new GrpcChannelOptions
|
||||
{
|
||||
var channel = GrpcChannel.ForAddress(
|
||||
"https://" + url,
|
||||
new GrpcChannelOptions {
|
||||
HttpHandler = new GrpcWebHandler(mode, new HttpClientHandler()),
|
||||
Credentials = sslCreds,
|
||||
MaxReceiveMessageSize = null
|
||||
@@ -48,16 +52,14 @@ public class EagleConnection : IDisposable
|
||||
return invoker;
|
||||
}
|
||||
|
||||
public EagleConnection(string playerName, string password, string url)
|
||||
{
|
||||
public EagleConnection(string playerName, string password, string url) {
|
||||
PlayerName = playerName;
|
||||
Url = url;
|
||||
|
||||
Credentials = new Metadata();
|
||||
Credentials.Add("user", playerName);
|
||||
|
||||
if (!loggerSet)
|
||||
{
|
||||
if (!loggerSet) {
|
||||
loggerSet = true;
|
||||
|
||||
string dir = Path.Combine(Application.persistentDataPath, "eagle0", "Resources");
|
||||
@@ -70,23 +72,24 @@ public class EagleConnection : IDisposable
|
||||
}
|
||||
|
||||
EagleGrpcClient = new Eagle.EagleClient(MakeInvoker(playerName, password, url));
|
||||
ShardokInternalInterfaceGrpcClient = new ShardokInternalInterface.ShardokInternalInterfaceClient(MakeInvoker(playerName, password, url));
|
||||
ShardokInternalInterfaceGrpcClient =
|
||||
new ShardokInternalInterface.ShardokInternalInterfaceClient(
|
||||
MakeInvoker(playerName, password, url));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
public void Dispose() {
|
||||
// GrpcEnvironment.SetLogger(null);
|
||||
}
|
||||
|
||||
// Used for bypassing the lobby screen
|
||||
public async Task<GameInfo> FirstRunningGame()
|
||||
{
|
||||
public async Task<GameInfo> FirstRunningGame() {
|
||||
SslCredentials sslCreds = new SslCredentials();
|
||||
|
||||
using (var call = EagleGrpcClient.EnterLobby(new GamesRequest(), cancellationToken: EagleCancellationToken))
|
||||
{
|
||||
while (repeatedCallback != null && await streamingCall.ResponseStream.MoveNext(cancellationToken: EagleCancellationToken))
|
||||
{
|
||||
using (var call = EagleGrpcClient.EnterLobby(
|
||||
new GamesRequest(),
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
while (repeatedCallback != null && await streamingCall.ResponseStream.MoveNext(
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
return streamingCall.ResponseStream.Current.RunningGames[0];
|
||||
}
|
||||
}
|
||||
@@ -94,53 +97,44 @@ public class EagleConnection : IDisposable
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> EnterLobby(Action<GamesReply, StatusCode> rc)
|
||||
{
|
||||
public async Task<bool> EnterLobby(Action<GamesReply, StatusCode> rc) {
|
||||
SslCredentials sslCreds = new SslCredentials();
|
||||
|
||||
using (var call = EagleGrpcClient.EnterLobby(new Net.Eagle0.Eagle.Api.GamesRequest(), cancellationToken: EagleCancellationToken))
|
||||
{
|
||||
using (var call = EagleGrpcClient.EnterLobby(
|
||||
new Net.Eagle0.Eagle.Api.GamesRequest(),
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
repeatedCallback = rc;
|
||||
streamingCall = call;
|
||||
|
||||
try
|
||||
{
|
||||
while (repeatedCallback != null && await streamingCall.ResponseStream.MoveNext(cancellationToken: EagleCancellationToken))
|
||||
{
|
||||
if (repeatedCallback != null)
|
||||
{
|
||||
repeatedCallback.Invoke(streamingCall.ResponseStream.Current, StatusCode.OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (streamingCall != null)
|
||||
{
|
||||
try {
|
||||
while (repeatedCallback != null &&
|
||||
await streamingCall.ResponseStream.MoveNext(
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
if (repeatedCallback != null) {
|
||||
repeatedCallback.Invoke(
|
||||
streamingCall.ResponseStream.Current,
|
||||
StatusCode.OK);
|
||||
} else {
|
||||
if (streamingCall != null) {
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
switch (e.StatusCode)
|
||||
{
|
||||
} catch (RpcException e) {
|
||||
switch (e.StatusCode) {
|
||||
case StatusCode.Cancelled:
|
||||
case StatusCode.Internal:
|
||||
if (repeatedCallback != null)
|
||||
{
|
||||
if (repeatedCallback != null) {
|
||||
repeatedCallback.Invoke(null, e.StatusCode);
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
if (e.StatusCode == StatusCode.Internal)
|
||||
{
|
||||
if (e.StatusCode == StatusCode.Internal) {
|
||||
Console.WriteLine("wut: {e}");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Console.WriteLine("Something went very wrong, caught exception {e}");
|
||||
}
|
||||
return false;
|
||||
@@ -149,11 +143,9 @@ public class EagleConnection : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public void LeaveLobby()
|
||||
{
|
||||
public void LeaveLobby() {
|
||||
repeatedCallback = null;
|
||||
if (streamingCall != null)
|
||||
{
|
||||
if (streamingCall != null) {
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
}
|
||||
|
||||
+101
-140
@@ -1,16 +1,16 @@
|
||||
/// Credit glennpow, Zarlang
|
||||
/// Sourced from - http://forum.unity3d.com/threads/free-script-particle-systems-in-ui-screen-space-overlay.406862/
|
||||
/// Sourced from -
|
||||
/// http://forum.unity3d.com/threads/free-script-particle-systems-in-ui-screen-space-overlay.406862/
|
||||
/// Updated by Zarlang with a more robust implementation, including TextureSheet annimation support
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
namespace UnityEngine.UI.Extensions {
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(CanvasRenderer), typeof(ParticleSystem))]
|
||||
[AddComponentMenu("UI/Effects/Extensions/UIParticleSystem")]
|
||||
public class UIParticleSystem : MaskableGraphic
|
||||
{
|
||||
[Tooltip("Having this enabled run the system in LateUpdate rather than in Update making it faster but less precise (more clunky)")]
|
||||
public class UIParticleSystem : MaskableGraphic {
|
||||
[Tooltip(
|
||||
"Having this enabled run the system in LateUpdate rather than in Update making it faster but less precise (more clunky)")]
|
||||
public bool fixedTime = true;
|
||||
|
||||
[Tooltip("Enables 3d rotation for the particles")]
|
||||
@@ -35,60 +35,37 @@ namespace UnityEngine.UI.Extensions
|
||||
private ParticleSystem.MainModule mainModule;
|
||||
#endif
|
||||
|
||||
public override Texture mainTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentTexture;
|
||||
}
|
||||
public override Texture mainTexture {
|
||||
get { return currentTexture; }
|
||||
}
|
||||
|
||||
protected bool Initialize()
|
||||
{
|
||||
protected bool Initialize() {
|
||||
// initialize members
|
||||
if (_transform == null)
|
||||
{
|
||||
_transform = transform;
|
||||
}
|
||||
if (pSystem == null)
|
||||
{
|
||||
if (_transform == null) { _transform = transform; }
|
||||
if (pSystem == null) {
|
||||
pSystem = GetComponent<ParticleSystem>();
|
||||
|
||||
if (pSystem == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (pSystem == null) { return false; }
|
||||
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
mainModule = pSystem.main;
|
||||
if (pSystem.main.maxParticles > 14000)
|
||||
{
|
||||
mainModule.maxParticles = 14000;
|
||||
}
|
||||
if (pSystem.main.maxParticles > 14000) { mainModule.maxParticles = 14000; }
|
||||
#else
|
||||
if (pSystem.maxParticles > 14000)
|
||||
pSystem.maxParticles = 14000;
|
||||
if (pSystem.maxParticles > 14000) pSystem.maxParticles = 14000;
|
||||
#endif
|
||||
|
||||
pRenderer = pSystem.GetComponent<ParticleSystemRenderer>();
|
||||
if (pRenderer != null)
|
||||
pRenderer.enabled = false;
|
||||
if (pRenderer != null) pRenderer.enabled = false;
|
||||
|
||||
if (material == null)
|
||||
{
|
||||
if (material == null) {
|
||||
var foundShader = Shader.Find("UI Extensions/Particles/Additive");
|
||||
if (foundShader)
|
||||
{
|
||||
material = new Material(foundShader);
|
||||
}
|
||||
if (foundShader) { material = new Material(foundShader); }
|
||||
}
|
||||
|
||||
currentMaterial = material;
|
||||
if (currentMaterial && currentMaterial.HasProperty("_MainTex"))
|
||||
{
|
||||
if (currentMaterial && currentMaterial.HasProperty("_MainTex")) {
|
||||
currentTexture = currentMaterial.mainTexture;
|
||||
if (currentTexture == null)
|
||||
currentTexture = Texture2D.whiteTexture;
|
||||
if (currentTexture == null) currentTexture = Texture2D.whiteTexture;
|
||||
}
|
||||
material = currentMaterial;
|
||||
// automatically set scaling
|
||||
@@ -104,8 +81,7 @@ namespace UnityEngine.UI.Extensions
|
||||
if (particles == null)
|
||||
particles = new ParticleSystem.Particle[pSystem.main.maxParticles];
|
||||
#else
|
||||
if (particles == null)
|
||||
particles = new ParticleSystem.Particle[pSystem.maxParticles];
|
||||
if (particles == null) particles = new ParticleSystem.Particle[pSystem.maxParticles];
|
||||
#endif
|
||||
|
||||
imageUV = new Vector4(0, 0, 1, 1);
|
||||
@@ -114,44 +90,34 @@ namespace UnityEngine.UI.Extensions
|
||||
textureSheetAnimation = pSystem.textureSheetAnimation;
|
||||
textureSheetAnimationFrames = 0;
|
||||
textureSheetAnimationFrameSize = Vector2.zero;
|
||||
if (textureSheetAnimation.enabled)
|
||||
{
|
||||
textureSheetAnimationFrames = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY;
|
||||
textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY);
|
||||
if (textureSheetAnimation.enabled) {
|
||||
textureSheetAnimationFrames =
|
||||
textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY;
|
||||
textureSheetAnimationFrameSize = new Vector2(
|
||||
1f / textureSheetAnimation.numTilesX,
|
||||
1f / textureSheetAnimation.numTilesY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
protected override void Awake() {
|
||||
base.Awake();
|
||||
if (!Initialize())
|
||||
enabled = false;
|
||||
if (!Initialize()) enabled = false;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
protected override void OnPopulateMesh(VertexHelper vh) {
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Application.isPlaying) {
|
||||
if (!Initialize()) { return; }
|
||||
}
|
||||
#endif
|
||||
// prepare vertices
|
||||
vh.Clear();
|
||||
|
||||
if (!gameObject.activeInHierarchy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!gameObject.activeInHierarchy) { return; }
|
||||
|
||||
if (!isInitialised && !pSystem.main.playOnAwake)
|
||||
{
|
||||
if (!isInitialised && !pSystem.main.playOnAwake) {
|
||||
pSystem.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
isInitialised = true;
|
||||
}
|
||||
@@ -162,15 +128,20 @@ namespace UnityEngine.UI.Extensions
|
||||
// iterate through current particles
|
||||
int count = pSystem.GetParticles(particles);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ParticleSystem.Particle particle = particles[i];
|
||||
|
||||
// get particle properties
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
Vector2 position = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
|
||||
Vector2 position =
|
||||
(mainModule.simulationSpace == ParticleSystemSimulationSpace.Local
|
||||
? particle.position
|
||||
: _transform.InverseTransformPoint(particle.position));
|
||||
#else
|
||||
Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
|
||||
Vector2 position =
|
||||
(pSystem.simulationSpace == ParticleSystemSimulationSpace.Local
|
||||
? particle.position
|
||||
: _transform.InverseTransformPoint(particle.position));
|
||||
#endif
|
||||
float rotation = -particle.rotation * Mathf.Deg2Rad;
|
||||
float rotation90 = rotation + Mathf.PI / 2;
|
||||
@@ -188,53 +159,55 @@ namespace UnityEngine.UI.Extensions
|
||||
|
||||
// apply texture sheet animation
|
||||
Vector4 particleUV = imageUV;
|
||||
if (textureSheetAnimation.enabled)
|
||||
{
|
||||
if (textureSheetAnimation.enabled) {
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime);
|
||||
|
||||
if (textureSheetAnimation.frameOverTime.curveMin != null)
|
||||
{
|
||||
frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
|
||||
}
|
||||
else if (textureSheetAnimation.frameOverTime.curve != null)
|
||||
{
|
||||
frameProgress = textureSheetAnimation.frameOverTime.curve.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
|
||||
}
|
||||
else if (textureSheetAnimation.frameOverTime.constant > 0)
|
||||
{
|
||||
frameProgress = textureSheetAnimation.frameOverTime.constant - (particle.remainingLifetime / particle.startLifetime);
|
||||
if (textureSheetAnimation.frameOverTime.curveMin != null) {
|
||||
frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(
|
||||
1 - (particle.remainingLifetime / particle.startLifetime));
|
||||
} else if (textureSheetAnimation.frameOverTime.curve != null) {
|
||||
frameProgress = textureSheetAnimation.frameOverTime.curve.Evaluate(
|
||||
1 - (particle.remainingLifetime / particle.startLifetime));
|
||||
} else if (textureSheetAnimation.frameOverTime.constant > 0) {
|
||||
frameProgress = textureSheetAnimation.frameOverTime.constant -
|
||||
(particle.remainingLifetime / particle.startLifetime);
|
||||
}
|
||||
#else
|
||||
float frameProgress = 1 - (particle.lifetime / particle.startLifetime);
|
||||
#endif
|
||||
|
||||
frameProgress = Mathf.Repeat(frameProgress * textureSheetAnimation.cycleCount, 1);
|
||||
frameProgress =
|
||||
Mathf.Repeat(frameProgress * textureSheetAnimation.cycleCount, 1);
|
||||
int frame = 0;
|
||||
|
||||
switch (textureSheetAnimation.animation)
|
||||
{
|
||||
|
||||
switch (textureSheetAnimation.animation) {
|
||||
case ParticleSystemAnimationType.WholeSheet:
|
||||
frame = Mathf.FloorToInt(frameProgress * textureSheetAnimationFrames);
|
||||
break;
|
||||
|
||||
case ParticleSystemAnimationType.SingleRow:
|
||||
frame = Mathf.FloorToInt(frameProgress * textureSheetAnimation.numTilesX);
|
||||
frame = Mathf.FloorToInt(
|
||||
frameProgress * textureSheetAnimation.numTilesX);
|
||||
|
||||
int row = textureSheetAnimation.rowIndex;
|
||||
// if (textureSheetAnimation.useRandomRow) { // FIXME - is this handled internally by rowIndex?
|
||||
// row = Random.Range(0, textureSheetAnimation.numTilesY, using: particle.randomSeed);
|
||||
// if (textureSheetAnimation.useRandomRow) { // FIXME
|
||||
// - is this handled internally by rowIndex?
|
||||
// row = Random.Range(0,
|
||||
// textureSheetAnimation.numTilesY, using:
|
||||
// particle.randomSeed);
|
||||
// }
|
||||
frame += row * textureSheetAnimation.numTilesX;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
frame %= textureSheetAnimationFrames;
|
||||
|
||||
particleUV.x = (frame % textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.x;
|
||||
particleUV.y = 1.0f - Mathf.FloorToInt(frame / textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.y;
|
||||
particleUV.x = (frame % textureSheetAnimation.numTilesX) *
|
||||
textureSheetAnimationFrameSize.x;
|
||||
particleUV.y =
|
||||
1.0f - Mathf.FloorToInt(frame / textureSheetAnimation.numTilesX) *
|
||||
textureSheetAnimationFrameSize.y;
|
||||
particleUV.z = particleUV.x + textureSheetAnimationFrameSize.x;
|
||||
particleUV.w = particleUV.y + textureSheetAnimationFrameSize.y;
|
||||
}
|
||||
@@ -264,8 +237,7 @@ namespace UnityEngine.UI.Extensions
|
||||
_quad[3].color = color;
|
||||
_quad[3].uv0 = temp;
|
||||
|
||||
if (rotation == 0)
|
||||
{
|
||||
if (rotation == 0) {
|
||||
// no rotation
|
||||
corner1.x = position.x - size;
|
||||
corner1.y = position.y - size;
|
||||
@@ -284,16 +256,19 @@ namespace UnityEngine.UI.Extensions
|
||||
temp.x = corner2.x;
|
||||
temp.y = corner1.y;
|
||||
_quad[3].position = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (use3dRotation)
|
||||
{
|
||||
} else {
|
||||
if (use3dRotation) {
|
||||
// get particle properties
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
Vector3 pos3d = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
|
||||
Vector3 pos3d =
|
||||
(mainModule.simulationSpace == ParticleSystemSimulationSpace.Local
|
||||
? particle.position
|
||||
: _transform.InverseTransformPoint(particle.position));
|
||||
#else
|
||||
Vector3 pos3d = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
|
||||
Vector3 pos3d =
|
||||
(pSystem.simulationSpace == ParticleSystemSimulationSpace.Local
|
||||
? particle.position
|
||||
: _transform.InverseTransformPoint(particle.position));
|
||||
#endif
|
||||
|
||||
// apply scale
|
||||
@@ -305,8 +280,7 @@ namespace UnityEngine.UI.Extensions
|
||||
position /= canvas.scaleFactor;
|
||||
#endif
|
||||
|
||||
Vector3[] verts = new Vector3[4]
|
||||
{
|
||||
Vector3[] verts = new Vector3[4] {
|
||||
new Vector3(-size, -size, 0),
|
||||
new Vector3(-size, size, 0),
|
||||
new Vector3(size, size, 0),
|
||||
@@ -319,12 +293,12 @@ namespace UnityEngine.UI.Extensions
|
||||
_quad[1].position = pos3d + particleRotation * verts[1];
|
||||
_quad[2].position = pos3d + particleRotation * verts[2];
|
||||
_quad[3].position = pos3d + particleRotation * verts[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// apply rotation
|
||||
Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size;
|
||||
Vector2 up = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;
|
||||
Vector2 right =
|
||||
new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size;
|
||||
Vector2 up =
|
||||
new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;
|
||||
|
||||
_quad[0].position = position - right - up;
|
||||
_quad[1].position = position - right + up;
|
||||
@@ -337,66 +311,53 @@ namespace UnityEngine.UI.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!fixedTime && Application.isPlaying)
|
||||
{
|
||||
private void Update() {
|
||||
if (!fixedTime && Application.isPlaying) {
|
||||
pSystem.Simulate(Time.unscaledDeltaTime, false, false, true);
|
||||
SetAllDirty();
|
||||
|
||||
if ((currentMaterial != null && currentTexture != currentMaterial.mainTexture) ||
|
||||
(material != null && currentMaterial != null && material.shader != currentMaterial.shader))
|
||||
{
|
||||
(material != null && currentMaterial != null &&
|
||||
material.shader != currentMaterial.shader)) {
|
||||
pSystem = null;
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
private void LateUpdate() {
|
||||
if (!Application.isPlaying) {
|
||||
SetAllDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fixedTime)
|
||||
{
|
||||
} else {
|
||||
if (fixedTime) {
|
||||
pSystem.Simulate(Time.unscaledDeltaTime, false, false, true);
|
||||
SetAllDirty();
|
||||
if ((currentMaterial != null && currentTexture != currentMaterial.mainTexture) ||
|
||||
(material != null && currentMaterial != null && material.shader != currentMaterial.shader))
|
||||
{
|
||||
if ((currentMaterial != null &&
|
||||
currentTexture != currentMaterial.mainTexture) ||
|
||||
(material != null && currentMaterial != null &&
|
||||
material.shader != currentMaterial.shader)) {
|
||||
pSystem = null;
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (material == currentMaterial)
|
||||
return;
|
||||
if (material == currentMaterial) return;
|
||||
pSystem = null;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
protected override void OnDestroy() {
|
||||
currentMaterial = null;
|
||||
currentTexture = null;
|
||||
}
|
||||
|
||||
public void StartParticleEmission()
|
||||
{
|
||||
pSystem.Play();
|
||||
}
|
||||
public void StartParticleEmission() { pSystem.Play(); }
|
||||
|
||||
public void StopParticleEmission()
|
||||
{
|
||||
public void StopParticleEmission() {
|
||||
pSystem.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
}
|
||||
|
||||
public void PauseParticleEmission()
|
||||
{
|
||||
public void PauseParticleEmission() {
|
||||
pSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-23
@@ -4,45 +4,35 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class CtrPanel : MonoBehaviour
|
||||
{
|
||||
public class CtrPanel : MonoBehaviour {
|
||||
private int page = 0;
|
||||
private List<GameObject> panels = new List<GameObject>();
|
||||
private TextMeshProUGUI textTitle;
|
||||
public Transform panelTransform;
|
||||
private bool isReady = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
private void Start() {
|
||||
textTitle = transform.GetComponentInChildren<TextMeshProUGUI>();
|
||||
|
||||
foreach (Transform t in panelTransform)
|
||||
{
|
||||
panels.Add(t.gameObject);
|
||||
}
|
||||
foreach (Transform t in panelTransform) { panels.Add(t.gameObject); }
|
||||
|
||||
isReady = true;
|
||||
|
||||
SetTitle();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
void Update() {
|
||||
if (panels.Count <= 0 || !isReady) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
|
||||
Click_Prev();
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
} else if (Input.GetKeyDown(KeyCode.RightArrow)) {
|
||||
Click_Next();
|
||||
}
|
||||
}
|
||||
|
||||
//이전
|
||||
public void Click_Prev()
|
||||
{
|
||||
public void Click_Prev() {
|
||||
if (page <= 0 || !isReady) return;
|
||||
|
||||
panels[page].SetActive(false);
|
||||
@@ -53,8 +43,7 @@ public class CtrPanel : MonoBehaviour
|
||||
}
|
||||
|
||||
//다음
|
||||
public void Click_Next()
|
||||
{
|
||||
public void Click_Next() {
|
||||
if (page >= panels.Count - 1) return;
|
||||
|
||||
panels[page].SetActive(false);
|
||||
@@ -64,8 +53,5 @@ public class CtrPanel : MonoBehaviour
|
||||
}
|
||||
|
||||
//하단 제목 설정
|
||||
private void SetTitle()
|
||||
{
|
||||
textTitle.text = panels[page].name;
|
||||
}
|
||||
private void SetTitle() { textTitle.text = panels[page].name; }
|
||||
}
|
||||
|
||||
@@ -3,88 +3,58 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MainQueue : MonoBehaviour
|
||||
{
|
||||
public class MainQueue : MonoBehaviour {
|
||||
static MainQueue __singletonInstance;
|
||||
Queue<Action> actionQueue = new Queue<Action>();
|
||||
Queue<Action> nextUpdateQueue = new Queue<Action>();
|
||||
|
||||
private MainQueue() {}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (__singletonInstance == null)
|
||||
{
|
||||
__singletonInstance = this;
|
||||
}
|
||||
void Awake() {
|
||||
if (__singletonInstance == null) { __singletonInstance = this; }
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
void Update() {
|
||||
Action possibleAction;
|
||||
do
|
||||
{
|
||||
do {
|
||||
possibleAction = null;
|
||||
lock (actionQueue)
|
||||
{
|
||||
if (actionQueue.Count > 0)
|
||||
{
|
||||
possibleAction = actionQueue.Dequeue();
|
||||
}
|
||||
lock (actionQueue) {
|
||||
if (actionQueue.Count > 0) { possibleAction = actionQueue.Dequeue(); }
|
||||
}
|
||||
|
||||
if (possibleAction != null)
|
||||
{
|
||||
possibleAction.Invoke();
|
||||
}
|
||||
if (possibleAction != null) { possibleAction.Invoke(); }
|
||||
} while (possibleAction != null);
|
||||
|
||||
lock (nextUpdateQueue)
|
||||
{
|
||||
foreach (Action action in nextUpdateQueue)
|
||||
{
|
||||
Enqueue(action);
|
||||
}
|
||||
lock (nextUpdateQueue) {
|
||||
foreach (Action action in nextUpdateQueue) { Enqueue(action); }
|
||||
|
||||
nextUpdateQueue.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public int Enqueue(Action newAction)
|
||||
{
|
||||
lock (actionQueue)
|
||||
{
|
||||
public int Enqueue(Action newAction) {
|
||||
lock (actionQueue) {
|
||||
actionQueue.Enqueue(newAction);
|
||||
|
||||
return actionQueue.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public int EnqueueForNextUpdate(Action newAction)
|
||||
{
|
||||
lock (nextUpdateQueue)
|
||||
{
|
||||
public int EnqueueForNextUpdate(Action newAction) {
|
||||
lock (nextUpdateQueue) {
|
||||
nextUpdateQueue.Enqueue(newAction);
|
||||
|
||||
return nextUpdateQueue.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public static MainQueue Q
|
||||
{
|
||||
get
|
||||
{
|
||||
if (__singletonInstance == null)
|
||||
{
|
||||
throw new Exception("No singleton found!");
|
||||
}
|
||||
public static MainQueue Q {
|
||||
get {
|
||||
if (__singletonInstance == null) { throw new Exception("No singleton found!"); }
|
||||
return __singletonInstance;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
__singletonInstance = null;
|
||||
}
|
||||
void OnDestroy() { __singletonInstance = null; }
|
||||
}
|
||||
|
||||
@@ -14,12 +14,13 @@ using SimpleFileBrowser;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
{
|
||||
public class MapEditorController : MonoBehaviour, IClickReceiver {
|
||||
public static readonly int ATTACKER_ID_COUNT = 8;
|
||||
|
||||
public HexGrid hexGrid;
|
||||
public HexGrid HexGrid { get { return hexGrid; } }
|
||||
public HexGrid HexGrid {
|
||||
get { return hexGrid; }
|
||||
}
|
||||
public MouseHandler mouseHandlerPrefab;
|
||||
|
||||
public Text mapInfoLabel;
|
||||
@@ -72,8 +73,7 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
|
||||
public WeatherPanelController weatherPanel;
|
||||
|
||||
enum SelectionMode
|
||||
{
|
||||
enum SelectionMode {
|
||||
plains = 0,
|
||||
hills = 1,
|
||||
forest = 2,
|
||||
@@ -88,36 +88,33 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
fire = 11,
|
||||
attackerStartingPositions = 12,
|
||||
defenderStartingPositions = 13,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
private TerrainType terrainTypeFromSelectionMode(SelectionMode mode)
|
||||
{
|
||||
private TerrainType terrainTypeFromSelectionMode(SelectionMode mode) {
|
||||
return (TerrainType)((int)mode + (int)TerrainType.Plains);
|
||||
}
|
||||
|
||||
private SelectionMode selectionMode;
|
||||
public int selectedAttackerId = 0;
|
||||
|
||||
public void SelectAttackerId(int index)
|
||||
{
|
||||
public void SelectAttackerId(int index) {
|
||||
selectedAttackerId = index;
|
||||
SelectTerrainTypeButton((int)SelectionMode.attackerStartingPositions);
|
||||
}
|
||||
|
||||
void SetUpGridFromMap()
|
||||
{
|
||||
void SetUpGridFromMap() {
|
||||
System.Random rnd = new System.Random();
|
||||
Texture[] textures = new Texture[map.RowCount * map.ColumnCount];
|
||||
randomNumberForCellIndex.Clear();
|
||||
for (int row = 0; row < map.RowCount; row++)
|
||||
{
|
||||
for (int column = 0; column < map.ColumnCount; column++)
|
||||
{
|
||||
for (int row = 0; row < map.RowCount; row++) {
|
||||
for (int column = 0; column < map.ColumnCount; column++) {
|
||||
int randomNumber = rnd.Next();
|
||||
randomNumberForCellIndex.Add(randomNumber);
|
||||
var tileTerrain = map.Terrain[row * map.ColumnCount + column];
|
||||
int cellIndex = (map.RowCount - 1 - row) * map.ColumnCount + column;
|
||||
textures[cellIndex] = imageForTerrainTracker.GetImageForTerrain(tileTerrain, randomNumber, Month);
|
||||
textures[cellIndex] =
|
||||
imageForTerrainTracker.GetImageForTerrain(tileTerrain, randomNumber, Month);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,59 +125,55 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
hexGrid.SetUp();
|
||||
|
||||
Coords coords = new Coords();
|
||||
for (int row = 0; row < map.RowCount; row++)
|
||||
{
|
||||
for (int row = 0; row < map.RowCount; row++) {
|
||||
coords.Row = row;
|
||||
for (int column = 0; column < map.ColumnCount; column++)
|
||||
{
|
||||
for (int column = 0; column < map.ColumnCount; column++) {
|
||||
coords.Column = column;
|
||||
|
||||
var modifier = map.Terrain[row * map.ColumnCount + column].Modifier;
|
||||
hexGrid.SetCellModifierImage(MapCoordsToGridIndex(coords), modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(MapCoordsToGridIndex(coords), modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
hexGrid.SetCellModifierImage(
|
||||
MapCoordsToGridIndex(coords),
|
||||
modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(
|
||||
MapCoordsToGridIndex(coords),
|
||||
modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
|
||||
int randomNumber = rnd.Next();
|
||||
randomNumberForCellIndex.Add(randomNumber);
|
||||
var tileTerrain = map.Terrain[row * map.ColumnCount + column];
|
||||
int cellIndex = (map.RowCount - 1 - row) * map.ColumnCount + column;
|
||||
textures[cellIndex] = imageForTerrainTracker.GetImageForTerrain(tileTerrain, randomNumber, Month);
|
||||
textures[cellIndex] =
|
||||
imageForTerrainTracker.GetImageForTerrain(tileTerrain, randomNumber, Month);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateStartingPositions();
|
||||
}
|
||||
|
||||
private HexMap NewHexMap()
|
||||
{
|
||||
private HexMap NewHexMap() {
|
||||
var newMap = new HexMap();
|
||||
newMap.RowCount = ROW_COUNT;
|
||||
newMap.ColumnCount = COLUMN_COUNT;
|
||||
newMap.DefenderStartingPositions = new StartingPositionList();
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++)
|
||||
{
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++) {
|
||||
newMap.AttackerStartingPositions.Add(new StartingPositionList());
|
||||
}
|
||||
|
||||
for (int i = 0; i < newMap.RowCount * newMap.ColumnCount; i++)
|
||||
{
|
||||
for (int i = 0; i < newMap.RowCount * newMap.ColumnCount; i++) {
|
||||
var terrain = new Net.Eagle0.Shardok.Common.Terrain();
|
||||
terrain.Type = TerrainType.Plains;
|
||||
terrain.Modifier = new TileModifier();
|
||||
newMap.Terrain.Add(terrain);
|
||||
}
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
newMap.MonthlyWeather.Add(
|
||||
new MonthlyWeather
|
||||
{
|
||||
for (int i = 0; i < 12; i++) {
|
||||
newMap.MonthlyWeather.Add(new MonthlyWeather {
|
||||
AverageTemperature = 50,
|
||||
SunChance = 40,
|
||||
CloudsChance = 30,
|
||||
RainChance = 20,
|
||||
ThunderstormChance = 10,
|
||||
MaxWindMph = 25
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
weatherPanel.MonthlyWeathers = new List<MonthlyWeather>(newMap.MonthlyWeather);
|
||||
|
||||
@@ -188,8 +181,7 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
gameObject.GetComponentInChildren<MouseHandler>().clickReceiver = this;
|
||||
|
||||
workingFilePath = null;
|
||||
@@ -233,47 +225,36 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
SelectTerrainTypeButton(0);
|
||||
}
|
||||
|
||||
public void SelectTerrainTypeButton(int type)
|
||||
{
|
||||
public void SelectTerrainTypeButton(int type) {
|
||||
int previouslySelected = (int)selectionMode;
|
||||
|
||||
selectionMode = (SelectionMode)type;
|
||||
buttons[type].colors = selectedColorBlock;
|
||||
|
||||
if (previouslySelected != type)
|
||||
{
|
||||
if (previouslySelected != type) {
|
||||
buttons[previouslySelected].colors = unselectedColorBlock;
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleLongHover(int? gridIndex, Vector3 mousePosition)
|
||||
{
|
||||
}
|
||||
public void HandleLongHover(int? gridIndex, Vector3 mousePosition) {}
|
||||
|
||||
public void HandleLongUIHover(IEnumerable<GameObject> hoveredObjects)
|
||||
{
|
||||
public void HandleLongUIHover(IEnumerable<GameObject> hoveredObjects) {
|
||||
// button tooltip
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveAs()
|
||||
{
|
||||
public void SaveAs() {
|
||||
FileBrowser.SetFilters(true, new FileBrowser.Filter("Maps", ".e0mj"));
|
||||
FileBrowser.SetDefaultFilter(".e0mj");
|
||||
|
||||
StartCoroutine(ShowSaveDialogCoroutine());
|
||||
}
|
||||
|
||||
private bool SaveWithFilePath(string filePath)
|
||||
{
|
||||
private bool SaveWithFilePath(string filePath) {
|
||||
var blankModifier = new TileModifier();
|
||||
var savedMap = new HexMap(map);
|
||||
foreach (var terrain in savedMap.Terrain)
|
||||
{
|
||||
if (terrain.Modifier == blankModifier)
|
||||
{
|
||||
terrain.Modifier = null;
|
||||
}
|
||||
foreach (var terrain in savedMap.Terrain) {
|
||||
if (terrain.Modifier == blankModifier) { terrain.Modifier = null; }
|
||||
}
|
||||
savedMap.MonthlyWeather.Clear();
|
||||
savedMap.MonthlyWeather.AddRange(weatherPanel.MonthlyWeathers);
|
||||
@@ -295,44 +276,32 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
return true;
|
||||
}
|
||||
|
||||
IEnumerator ShowSaveDialogCoroutine()
|
||||
{
|
||||
IEnumerator ShowSaveDialogCoroutine() {
|
||||
var initialPath = PlayerPrefs.GetString("mapLocation", null);
|
||||
|
||||
FileBrowser.SetDefaultFilter(".e0mj");
|
||||
yield return FileBrowser.WaitForSaveDialog(FileBrowser.PickMode.Files, false, initialPath);
|
||||
|
||||
if (FileBrowser.Success)
|
||||
{
|
||||
if (FileBrowser.Success) {
|
||||
var path = FileBrowser.Result[0];
|
||||
if (Path.GetExtension(path) != ".e0mj")
|
||||
{
|
||||
path = Path.ChangeExtension(path, ".e0mj");
|
||||
}
|
||||
if (Path.GetExtension(path) != ".e0mj") { path = Path.ChangeExtension(path, ".e0mj"); }
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
PlayerPrefs.SetString("mapLocation", dirPath);
|
||||
|
||||
bool success = SaveWithFilePath(path);
|
||||
if (!success)
|
||||
{
|
||||
throw new ArgumentException("unable to save");
|
||||
}
|
||||
if (!success) { throw new ArgumentException("unable to save"); }
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
SaveWithFilePath(workingFilePath);
|
||||
}
|
||||
public void Save() { SaveWithFilePath(workingFilePath); }
|
||||
|
||||
IEnumerator ShowLoadDialogCoroutine()
|
||||
{
|
||||
IEnumerator ShowLoadDialogCoroutine() {
|
||||
var initialPath = PlayerPrefs.GetString("mapLocation", null);
|
||||
|
||||
yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
yield return FileBrowser
|
||||
.WaitForLoadDialog(FileBrowser.PickMode.Files, false, initialPath, null);
|
||||
|
||||
if (FileBrowser.Success)
|
||||
{
|
||||
if (FileBrowser.Success) {
|
||||
hexGrid.ClearOverlays();
|
||||
var path = FileBrowser.Result[0];
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
@@ -342,8 +311,7 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
|
||||
var jp = new JsonParser(JsonParser.Settings.Default);
|
||||
map = jp.Parse<HexMap>(jsonText);
|
||||
while (map.AttackerStartingPositions.Count < ATTACKER_ID_COUNT)
|
||||
{
|
||||
while (map.AttackerStartingPositions.Count < ATTACKER_ID_COUNT) {
|
||||
map.AttackerStartingPositions.Add(new StartingPositionList());
|
||||
}
|
||||
|
||||
@@ -357,16 +325,14 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
}
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
public void Load() {
|
||||
FileBrowser.SetFilters(true, new FileBrowser.Filter("Maps", ".e0mj"));
|
||||
FileBrowser.SetDefaultFilter(".e0mj");
|
||||
|
||||
StartCoroutine(ShowLoadDialogCoroutine());
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
public void Reset() {
|
||||
hexGrid.ClearOverlays();
|
||||
hexGrid.ClearCellModifierImages();
|
||||
map = NewHexMap();
|
||||
@@ -378,18 +344,11 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
UpdateStartingPositions();
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
public void Quit() { Application.Quit(); }
|
||||
|
||||
public void WeatherClicked()
|
||||
{
|
||||
weatherPanel.gameObject.SetActive(true);
|
||||
}
|
||||
public void WeatherClicked() { weatherPanel.gameObject.SetActive(true); }
|
||||
|
||||
private void UpdateSaveInteractability()
|
||||
{
|
||||
private void UpdateSaveInteractability() {
|
||||
saveButton.interactable = false;
|
||||
saveAsButton.interactable = false;
|
||||
|
||||
@@ -397,11 +356,14 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
// Additionally, there must be at least two total starting position sets
|
||||
// (1 defender and 1+ attackers, or 2+ attackers)
|
||||
int playerCount = 0;
|
||||
if (map.DefenderStartingPositions.Positions.Count > 0 && map.DefenderStartingPositions.Positions.Count != 10) return;
|
||||
if (map.DefenderStartingPositions.Positions.Count > 0 &&
|
||||
map.DefenderStartingPositions.Positions.Count != 10)
|
||||
return;
|
||||
if (map.DefenderStartingPositions.Positions.Count > 0) playerCount++;
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++)
|
||||
{
|
||||
if (map.AttackerStartingPositions[i].Positions.Count > 0 && map.AttackerStartingPositions[i].Positions.Count != 10) return;
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++) {
|
||||
if (map.AttackerStartingPositions[i].Positions.Count > 0 &&
|
||||
map.AttackerStartingPositions[i].Positions.Count != 10)
|
||||
return;
|
||||
if (map.AttackerStartingPositions[i].Positions.Count > 0) playerCount++;
|
||||
}
|
||||
|
||||
@@ -409,21 +371,15 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
|
||||
saveAsButton.interactable = true;
|
||||
|
||||
if (!String.IsNullOrEmpty(workingFilePath))
|
||||
{
|
||||
saveButton.interactable = true;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(workingFilePath)) { saveButton.interactable = true; }
|
||||
}
|
||||
|
||||
public void LoadConfirm(string path)
|
||||
{
|
||||
public void LoadConfirm(string path) {
|
||||
hexGrid.ClearOverlays();
|
||||
using (var fileStream = File.OpenRead(path))
|
||||
using (CodedInputStream input = new CodedInputStream(fileStream))
|
||||
{
|
||||
using (var fileStream = File.OpenRead(path)) using (
|
||||
CodedInputStream input = new CodedInputStream(fileStream)) {
|
||||
map = HexMap.Parser.ParseFrom(input);
|
||||
while (map.AttackerStartingPositions.Count < ATTACKER_ID_COUNT)
|
||||
{
|
||||
while (map.AttackerStartingPositions.Count < ATTACKER_ID_COUNT) {
|
||||
map.AttackerStartingPositions.Add(new StartingPositionList());
|
||||
}
|
||||
}
|
||||
@@ -436,33 +392,24 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
UpdateStartingPositions();
|
||||
}
|
||||
|
||||
public void HandlePrimaryClick(int clickedIndex)
|
||||
{
|
||||
public void HandlePrimaryClick(int clickedIndex) {
|
||||
HandleUpdateToOneIndex(clickedIndex, includeTogglables: true);
|
||||
}
|
||||
|
||||
public void HandleSecondaryClick(int clickedIndex)
|
||||
{
|
||||
}
|
||||
public void HandleSecondaryClick(int clickedIndex) {}
|
||||
|
||||
private bool IsWater(TerrainType type)
|
||||
{
|
||||
private bool IsWater(TerrainType type) {
|
||||
return type == TerrainType.StillWater || type == TerrainType.River;
|
||||
}
|
||||
|
||||
private void HandleUpdateToOneIndex(int clickedIndex, bool includeTogglables)
|
||||
{
|
||||
if (!includeTogglables && selectionMode > SelectionMode.river)
|
||||
{
|
||||
return;
|
||||
}
|
||||
private void HandleUpdateToOneIndex(int clickedIndex, bool includeTogglables) {
|
||||
if (!includeTogglables && selectionMode > SelectionMode.river) { return; }
|
||||
|
||||
var newTerrain = map.Terrain[ProtoPositionFromGridIndex(clickedIndex)];
|
||||
var defenderPositions = map.DefenderStartingPositions.Positions;
|
||||
Coords coords = GridIndexToMapCoords(clickedIndex);
|
||||
|
||||
switch (selectionMode)
|
||||
{
|
||||
switch (selectionMode) {
|
||||
case SelectionMode.plains:
|
||||
case SelectionMode.forest:
|
||||
case SelectionMode.hills:
|
||||
@@ -475,92 +422,70 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
break;
|
||||
|
||||
case SelectionMode.stillWater:
|
||||
case SelectionMode.river:
|
||||
{
|
||||
case SelectionMode.river: {
|
||||
var oldBridge = newTerrain.Modifier.Bridge;
|
||||
|
||||
newTerrain = new Net.Eagle0.Shardok.Common.Terrain();
|
||||
newTerrain.Modifier = new TileModifier();
|
||||
if (oldBridge != null)
|
||||
{
|
||||
newTerrain.Modifier.Bridge = oldBridge;
|
||||
}
|
||||
if (oldBridge != null) { newTerrain.Modifier.Bridge = oldBridge; }
|
||||
|
||||
newTerrain.Type = terrainTypeFromSelectionMode(selectionMode);
|
||||
break;
|
||||
}
|
||||
|
||||
case SelectionMode.ice:
|
||||
if (!IsWater(newTerrain.Type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (newTerrain.Modifier?.Ice == null)
|
||||
{
|
||||
if (!IsWater(newTerrain.Type)) { return; }
|
||||
if (newTerrain.Modifier?.Ice == null) {
|
||||
if (newTerrain.Modifier == null) newTerrain.Modifier = new TileModifier();
|
||||
|
||||
newTerrain.Modifier.Ice = new TileModifier.Types.SingleModifier();
|
||||
newTerrain.Modifier.Ice.Integrity = 50;
|
||||
}
|
||||
else if (newTerrain.Modifier != null) newTerrain.Modifier.Ice = null;
|
||||
} else if (newTerrain.Modifier != null)
|
||||
newTerrain.Modifier.Ice = null;
|
||||
break;
|
||||
|
||||
case SelectionMode.bridge:
|
||||
if (!IsWater(newTerrain.Type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (newTerrain.Modifier?.Bridge == null)
|
||||
{
|
||||
if (!IsWater(newTerrain.Type)) { return; }
|
||||
if (newTerrain.Modifier?.Bridge == null) {
|
||||
if (newTerrain.Modifier == null) newTerrain.Modifier = new TileModifier();
|
||||
|
||||
newTerrain.Modifier.Bridge = new TileModifier.Types.SingleModifier();
|
||||
newTerrain.Modifier.Bridge.Integrity = 100.0;
|
||||
}
|
||||
else if (newTerrain.Modifier != null) newTerrain.Modifier.Bridge = null;
|
||||
} else if (newTerrain.Modifier != null)
|
||||
newTerrain.Modifier.Bridge = null;
|
||||
|
||||
break;
|
||||
|
||||
case SelectionMode.castle:
|
||||
if (newTerrain.Modifier?.Castle == null)
|
||||
{
|
||||
if (newTerrain.Modifier?.Castle == null) {
|
||||
if (newTerrain.Modifier == null) newTerrain.Modifier = new TileModifier();
|
||||
|
||||
newTerrain.Modifier.Castle = new TileModifier.Types.SingleModifier();
|
||||
newTerrain.Modifier.Castle.Integrity = 100.0;
|
||||
}
|
||||
else if (newTerrain.Modifier != null) newTerrain.Modifier.Castle = null;
|
||||
} else if (newTerrain.Modifier != null)
|
||||
newTerrain.Modifier.Castle = null;
|
||||
break;
|
||||
|
||||
case SelectionMode.fire:
|
||||
if (newTerrain.Modifier.Fire == null)
|
||||
{
|
||||
if (newTerrain.Modifier.Fire == null) {
|
||||
newTerrain.Modifier.Fire = new TileModifier.Types.SingleModifier();
|
||||
}
|
||||
else if (newTerrain.Modifier != null) newTerrain.Modifier.Fire = null;
|
||||
} else if (newTerrain.Modifier != null)
|
||||
newTerrain.Modifier.Fire = null;
|
||||
break;
|
||||
|
||||
case SelectionMode.attackerStartingPositions:
|
||||
if (defenderPositions.Contains(coords))
|
||||
{
|
||||
defenderPositions.Remove(coords);
|
||||
}
|
||||
if (defenderPositions.Contains(coords)) { defenderPositions.Remove(coords); }
|
||||
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++)
|
||||
{
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++) {
|
||||
if (i == selectedAttackerId) continue;
|
||||
if (map.AttackerStartingPositions[i].Positions.Contains(coords))
|
||||
{
|
||||
if (map.AttackerStartingPositions[i].Positions.Contains(coords)) {
|
||||
map.AttackerStartingPositions[i].Positions.Remove(coords);
|
||||
}
|
||||
}
|
||||
|
||||
if (map.AttackerStartingPositions[selectedAttackerId].Positions.Contains(coords))
|
||||
{
|
||||
if (map.AttackerStartingPositions[selectedAttackerId].Positions.Contains(coords)) {
|
||||
map.AttackerStartingPositions[selectedAttackerId].Positions.Remove(coords);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
map.AttackerStartingPositions[selectedAttackerId].Positions.Add(coords);
|
||||
}
|
||||
|
||||
@@ -568,20 +493,15 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
break;
|
||||
|
||||
case SelectionMode.defenderStartingPositions:
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++)
|
||||
{
|
||||
if (map.AttackerStartingPositions[i].Positions.Contains(coords))
|
||||
{
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++) {
|
||||
if (map.AttackerStartingPositions[i].Positions.Contains(coords)) {
|
||||
map.AttackerStartingPositions[i].Positions.Remove(coords);
|
||||
}
|
||||
}
|
||||
|
||||
if (defenderPositions.Contains(coords))
|
||||
{
|
||||
if (defenderPositions.Contains(coords)) {
|
||||
defenderPositions.Remove(coords);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
defenderPositions.Add(coords);
|
||||
}
|
||||
UpdateStartingPositions();
|
||||
@@ -589,76 +509,84 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
}
|
||||
|
||||
var imageTerrain = new Net.Eagle0.Shardok.Common.Terrain(newTerrain);
|
||||
if (snowToggle.isOn)
|
||||
{
|
||||
if (snowToggle.isOn) {
|
||||
if (imageTerrain.Modifier == null) imageTerrain.Modifier = new TileModifier();
|
||||
imageTerrain.Modifier.Snow = new TileModifier.Types.SingleModifier { Integrity = 50 };
|
||||
}
|
||||
var image = imageForTerrainTracker.GetImageForTerrain(imageTerrain, randomNumberForCellIndex[ProtoPositionFromGridIndex(clickedIndex)], Month);
|
||||
var image = imageForTerrainTracker.GetImageForTerrain(
|
||||
imageTerrain,
|
||||
randomNumberForCellIndex[ProtoPositionFromGridIndex(clickedIndex)],
|
||||
Month);
|
||||
|
||||
map.Terrain[ProtoPositionFromGridIndex(clickedIndex)] = newTerrain;
|
||||
hexGrid.SetCellTerrainImage(clickedIndex, image);
|
||||
hexGrid.SetCellModifierImage(clickedIndex, newTerrain.Modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(clickedIndex, newTerrain.Modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
hexGrid.SetCellModifierImage(
|
||||
clickedIndex,
|
||||
newTerrain.Modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(
|
||||
clickedIndex,
|
||||
newTerrain.Modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
}
|
||||
|
||||
private void RedrawAll()
|
||||
{
|
||||
for (int row = 0; row < map.RowCount; row++)
|
||||
{
|
||||
for (int column = 0; column < map.ColumnCount; column++)
|
||||
{
|
||||
private void RedrawAll() {
|
||||
for (int row = 0; row < map.RowCount; row++) {
|
||||
for (int column = 0; column < map.ColumnCount; column++) {
|
||||
int gridIndex = row * map.ColumnCount + column;
|
||||
int randomNumber = randomNumberForCellIndex[ProtoPositionFromGridIndex(gridIndex)];
|
||||
int cellIndex = (map.RowCount - 1 - row) * map.ColumnCount + column;
|
||||
|
||||
var imageTerrain = new Net.Eagle0.Shardok.Common.Terrain(map.Terrain[gridIndex]);
|
||||
if (snowToggle.isOn)
|
||||
{
|
||||
if (snowToggle.isOn) {
|
||||
if (imageTerrain.Modifier == null) imageTerrain.Modifier = new TileModifier();
|
||||
imageTerrain.Modifier.Snow = new TileModifier.Types.SingleModifier { Integrity = 50 };
|
||||
imageTerrain.Modifier.Snow =
|
||||
new TileModifier.Types.SingleModifier { Integrity = 50 };
|
||||
}
|
||||
|
||||
var image = imageForTerrainTracker.GetImageForTerrain(imageTerrain, randomNumber, Month);
|
||||
var image = imageForTerrainTracker.GetImageForTerrain(
|
||||
imageTerrain,
|
||||
randomNumber,
|
||||
Month);
|
||||
|
||||
hexGrid.SetCellTerrainImage(cellIndex, image);
|
||||
hexGrid.SetCellModifierImage(cellIndex, imageTerrain.Modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(cellIndex, imageTerrain.Modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
hexGrid.SetCellModifierImage(
|
||||
cellIndex,
|
||||
imageTerrain.Modifier?.Bridge == null ? null : bridgeImage);
|
||||
hexGrid.SetCellModifierEffect(
|
||||
cellIndex,
|
||||
imageTerrain.Modifier?.Fire == null ? null : fireEffectPrefab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStartingPositions()
|
||||
{
|
||||
private void UpdateStartingPositions() {
|
||||
int attackerCount = map.AttackerStartingPositions[selectedAttackerId].Positions.Count;
|
||||
int defenderCount = map.DefenderStartingPositions.Positions.Count;
|
||||
string attackerCountString = attackerCount.ToString();
|
||||
if (attackerCount == 0 || attackerCount == 10)
|
||||
{
|
||||
if (attackerCount == 0 || attackerCount == 10) {
|
||||
attackerCountString = $"<color=#00FF00FF>{attackerCountString}</color>";
|
||||
}
|
||||
string defenderCountString = defenderCount.ToString();
|
||||
if (defenderCount == 10)
|
||||
{
|
||||
if (defenderCount == 10) {
|
||||
attackerCountString = $"<color=#00FF00FF>{defenderCountString}</color>";
|
||||
}
|
||||
attackerStartingPositionsButton.GetComponentInChildren<Text>().text = $"Attacker Start Positions ({attackerCountString})";
|
||||
defenderStartingPositionsButton.GetComponentInChildren<Text>().text = $"Defender Start Positions ({defenderCountString})";
|
||||
attackerStartingPositionsButton.GetComponentInChildren<Text>().text =
|
||||
$"Attacker Start Positions ({attackerCountString})";
|
||||
defenderStartingPositionsButton.GetComponentInChildren<Text>().text =
|
||||
$"Defender Start Positions ({defenderCountString})";
|
||||
|
||||
hexGrid.ClearOverlays();
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++)
|
||||
{
|
||||
string text = $"{attackerStartingPositionsDropdown.options[i].text.Split(' ')[0]} ({map.AttackerStartingPositions[i].Positions.Count})";
|
||||
foreach (Coords attackerPosition in map.AttackerStartingPositions[i].Positions)
|
||||
{
|
||||
for (int i = 0; i < ATTACKER_ID_COUNT; i++) {
|
||||
string text =
|
||||
$"{attackerStartingPositionsDropdown.options[i].text.Split(' ')[0]} ({map.AttackerStartingPositions[i].Positions.Count})";
|
||||
foreach (Coords attackerPosition in map.AttackerStartingPositions[i].Positions) {
|
||||
int targetIndex = MapCoordsToGridIndex(attackerPosition);
|
||||
Color primaryColor = Color.Lerp(Color.red, Color.green, (i / (float)(ATTACKER_ID_COUNT - 1)));
|
||||
Color primaryColor =
|
||||
Color.Lerp(Color.red, Color.green, (i / (float)(ATTACKER_ID_COUNT - 1)));
|
||||
Color secondaryColor = Color.white;
|
||||
hexGrid.OverlayCell(targetIndex, primaryColor, secondaryColor, null, text);
|
||||
}
|
||||
}
|
||||
foreach (Coords defenderPosition in map.DefenderStartingPositions.Positions)
|
||||
{
|
||||
foreach (Coords defenderPosition in map.DefenderStartingPositions.Positions) {
|
||||
int targetIndex = MapCoordsToGridIndex(defenderPosition);
|
||||
Color secondaryColor = Color.white;
|
||||
hexGrid.OverlayCell(targetIndex, Color.black, secondaryColor, null, null);
|
||||
@@ -667,74 +595,61 @@ public class MapEditorController : MonoBehaviour, IClickReceiver
|
||||
UpdateSaveInteractability();
|
||||
}
|
||||
|
||||
public void HandleDrag(int startIndex, int finishIndex)
|
||||
{
|
||||
public void HandleDrag(int startIndex, int finishIndex) {
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void HandleHover(int gridIndex)
|
||||
{
|
||||
public void HandleHover(int gridIndex) {
|
||||
var terrain = map.Terrain[ProtoPositionFromGridIndex(gridIndex)];
|
||||
|
||||
string description = terrain.Type.ToString();
|
||||
if (terrain.Modifier?.Castle != null)
|
||||
{
|
||||
if (terrain.Modifier?.Castle != null) {
|
||||
description += $"<b> (Castle [{(int)terrain.Modifier.Castle.Integrity.Value}])</b>";
|
||||
}
|
||||
if (terrain.Modifier?.Fire != null)
|
||||
{
|
||||
if (terrain.Modifier?.Fire != null) {
|
||||
description += "<b><color=#FF0000FF> (Fire)</color></b>";
|
||||
}
|
||||
if (terrain.Modifier?.Ice != null)
|
||||
{
|
||||
description += $"<b><color=#0000FFFF> (Frozen [{(int)terrain.Modifier.Ice.Integrity.Value}])</color></b>";
|
||||
if (terrain.Modifier?.Ice != null) {
|
||||
description +=
|
||||
$"<b><color=#0000FFFF> (Frozen [{(int)terrain.Modifier.Ice.Integrity.Value}])</color></b>";
|
||||
}
|
||||
if (terrain.Modifier?.Snow != null)
|
||||
{
|
||||
description += $"<b><color=#0000FFFF> (Snow [{(int)terrain.Modifier.Snow.Integrity.Value}])</color></b>";
|
||||
if (terrain.Modifier?.Snow != null) {
|
||||
description +=
|
||||
$"<b><color=#0000FFFF> (Snow [{(int)terrain.Modifier.Snow.Integrity.Value}])</color></b>";
|
||||
}
|
||||
if (terrain.Modifier?.Bridge != null)
|
||||
{
|
||||
if (terrain.Modifier?.Bridge != null) {
|
||||
description += $"<b> (Bridge [{(int)terrain.Modifier.Bridge.Integrity.Value}])</b>";
|
||||
}
|
||||
|
||||
tileInfoText.text = description;
|
||||
}
|
||||
|
||||
public void RedrawCommandOverlays(int? mouseDownGridIndex, int? currentMouseGridIndex)
|
||||
{
|
||||
public void RedrawCommandOverlays(int? mouseDownGridIndex, int? currentMouseGridIndex) {
|
||||
HandleUpdateToOneIndex(currentMouseGridIndex.Value, includeTogglables: false);
|
||||
}
|
||||
|
||||
public void HandleMouseRightDownOnNewTile(int mouseDownGridIndex, int currentMouseGridIndex)
|
||||
{
|
||||
}
|
||||
public void HandleMouseRightDownOnNewTile(int mouseDownGridIndex, int currentMouseGridIndex) {}
|
||||
|
||||
public void WinterOrSnowToggled(bool value)
|
||||
{
|
||||
public void WinterOrSnowToggled(bool value) {
|
||||
snowToggle.interactable = winterToggle.isOn;
|
||||
RedrawAll();
|
||||
}
|
||||
|
||||
Coords GridIndexToMapCoords(int gridIndex)
|
||||
{
|
||||
Coords GridIndexToMapCoords(int gridIndex) {
|
||||
Coords coords = new Coords();
|
||||
coords.Row = map.RowCount - 1 - gridIndex / map.ColumnCount;
|
||||
coords.Column = gridIndex % map.ColumnCount;
|
||||
|
||||
return coords;
|
||||
}
|
||||
int ProtoPositionFromGridIndex(int gridIndex)
|
||||
{
|
||||
int ProtoPositionFromGridIndex(int gridIndex) {
|
||||
int row = map.RowCount - 1 - gridIndex / map.ColumnCount;
|
||||
int column = gridIndex % map.ColumnCount;
|
||||
|
||||
return row * map.ColumnCount + column;
|
||||
}
|
||||
int MapCoordsToGridIndex(Coords mapCoords)
|
||||
{
|
||||
int MapCoordsToGridIndex(Coords mapCoords) {
|
||||
int gridRow = map.RowCount - 1 - mapCoords.Row;
|
||||
return gridRow * map.ColumnCount + mapCoords.Column;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+250
-905
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user