Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UFrameIT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
UFrameIT
Commits
59002868
Commit
59002868
authored
2 years ago
by
Tobias Schöner
Browse files
Options
Downloads
Patches
Plain Diff
feat: Factscreen now reacts to grouping toggle
parent
00e1c5e2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assets/Resources/Prefabs/UI/Facts/Factscreen.prefab
+14
-2
14 additions, 2 deletions
Assets/Resources/Prefabs/UI/Facts/Factscreen.prefab
Assets/Scripts/InventoryStuff/DisplayFacts.cs
+110
-7
110 additions, 7 deletions
Assets/Scripts/InventoryStuff/DisplayFacts.cs
with
124 additions
and
9 deletions
Assets/Resources/Prefabs/UI/Facts/Factscreen.prefab
+
14
−
2
View file @
59002868
...
@@ -439,7 +439,7 @@ GameObject:
...
@@ -439,7 +439,7 @@ GameObject:
-
component
:
{
fileID
:
4370335918965838469
}
-
component
:
{
fileID
:
4370335918965838469
}
-
component
:
{
fileID
:
4267244877370467227
}
-
component
:
{
fileID
:
4267244877370467227
}
m_Layer
:
5
m_Layer
:
5
m_Name
:
Toggle
m_Name
:
Grouping
Toggle
m_TagString
:
Untagged
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
m_Icon
:
{
fileID
:
0
}
m_NavMeshLayer
:
0
m_NavMeshLayer
:
0
...
@@ -513,7 +513,19 @@ MonoBehaviour:
...
@@ -513,7 +513,19 @@ MonoBehaviour:
m_Group
:
{
fileID
:
0
}
m_Group
:
{
fileID
:
0
}
onValueChanged
:
onValueChanged
:
m_PersistentCalls
:
m_PersistentCalls
:
m_Calls
:
[]
m_Calls
:
-
m_Target
:
{
fileID
:
3581652732795482906
}
m_TargetAssemblyTypeName
:
DisplayFacts, Assembly-CSharp
m_MethodName
:
GroupingChanged
m_Mode
:
2
m_Arguments
:
m_ObjectArgument
:
{
fileID
:
4267244877370467227
}
m_ObjectArgumentAssemblyTypeName
:
UnityEngine.UI.Toggle, UnityEngine.UI
m_IntArgument
:
0
m_FloatArgument
:
0
m_StringArgument
:
m_BoolArgument
:
0
m_CallState
:
2
m_IsOn
:
0
m_IsOn
:
0
---
!u!1
&6430644988760938474
---
!u!1
&6430644988760938474
GameObject
:
GameObject
:
...
...
This diff is collapsed.
Click to expand it.
Assets/Scripts/InventoryStuff/DisplayFacts.cs
+
110
−
7
View file @
59002868
...
@@ -3,16 +3,20 @@
...
@@ -3,16 +3,20 @@
using
TMPro
;
using
TMPro
;
using
System
;
using
System
;
using
static
CommunicationEvents
;
using
static
CommunicationEvents
;
using
System.Linq
;
using
UnityEngine.UI
;
using
System.Collections
;
public
class
DisplayFacts
:
MonoBehaviour
public
class
DisplayFacts
:
MonoBehaviour
{
{
public
static
Dictionary
<
Type
,
GameObject
>
prefabDictionary
;
public
static
Dictionary
<
Type
,
GameObject
>
prefabDictionary
;
public
static
Dictionary
<
string
,
GameObject
>
displayedFacts
=
new
();
public
static
Dictionary
<
string
,
GameObject
>
displayedFacts
=
new
();
[
SerializeField
]
private
Transform
factscreenContent
;
[
SerializeField
]
private
GameObject
factSpotPrefab
;
[
SerializeField
]
private
GameObject
factSpotPrefab
;
public
Transform
factscreenContent
;
private
bool
showOnlyFavorites
=
false
;
private
bool
showGrouped
=
false
;
[
Header
(
"FactPrefabs"
)]
[
Header
(
"FactPrefabs"
)]
public
GameObject
prefab_Point
;
public
GameObject
prefab_Point
;
...
@@ -39,7 +43,7 @@ public class DisplayFacts : MonoBehaviour
...
@@ -39,7 +43,7 @@ public class DisplayFacts : MonoBehaviour
public
GameObject
prefab_TestFact
;
public
GameObject
prefab_TestFact
;
#
region
UnityMethods
//Start is called before the first frame update
//Start is called before the first frame update
void
Start
()
void
Start
()
{
{
...
@@ -70,18 +74,43 @@ void Start()
...
@@ -70,18 +74,43 @@ void Start()
AddFactEvent
.
AddListener
(
AddFact
);
AddFactEvent
.
AddListener
(
AddFact
);
RemoveFactEvent
.
AddListener
(
RemoveFact
);
RemoveFactEvent
.
AddListener
(
RemoveFact
);
AnimateExistingFactEvent
.
AddListener
(
AnimateFact
);
AnimateExistingFactEvent
.
AddListener
(
AnimateFact
);
FactFavorisation
.
ChangeFavoriteEvent
.
AddListener
(
OnFavoriteChange
);
}
}
#
endregion
UnityMethods
#
region
Implementation
ö
public
void
AddFact
(
Fact
fact
)
{
public
void
AddFact
(
Fact
fact
)
{
// index where the new display would be inserted if in showGroup is active
int
siblingIdx
=
0
;
if
(
showGrouped
)
{
var
facts
=
GetChildObjects
(
factscreenContent
.
transform
).
Select
(
c
=>
c
.
GetComponentInChildren
<
FactWrapper
>().
fact
).
ToList
();
siblingIdx
=
GetIndexInSortedList
(
fact
,
facts
);
}
// create display
var
display
=
CreateDisplay
(
transform
,
fact
);
var
display
=
CreateDisplay
(
transform
,
fact
);
display
.
transform
.
localPosition
=
Vector3
.
zero
;
display
.
transform
.
localPosition
=
Vector3
.
zero
;
displayedFacts
.
Add
(
fact
.
Id
,
display
);
displayedFacts
.
Add
(
fact
.
Id
,
display
);
// disable if showOnlyFavorites is true and fact is no favorite
display
.
transform
.
parent
.
gameObject
.
SetActive
(!(
showOnlyFavorites
&&
!
display
.
GetComponent
<
FactFavorisation
>().
IsFavorite
));
// if showGrouped is true: move to correct ordered position
if
(
showGrouped
)
display
.
transform
.
parent
.
transform
.
SetSiblingIndex
(
siblingIdx
);
}
private
GameObject
CreateDisplay
(
Transform
transform
,
Fact
fact
)
{
var
spot
=
Instantiate
(
factSpotPrefab
,
factscreenContent
);
return
fact
.
instantiateDisplay
(
prefabDictionary
[
fact
.
GetType
()],
spot
.
transform
);
}
}
public
void
RemoveFact
(
Fact
fact
)
public
void
RemoveFact
(
Fact
fact
)
{
{
// destroy factSpot (parent of displayed fact) and the fact display with it
// destroy factSpot (parent of displayed fact) and the fact display with it
Destroy
(
displayedFacts
[
fact
.
Id
].
transform
.
parent
);
Destroy
(
displayedFacts
[
fact
.
Id
].
transform
.
parent
.
gameObject
);
displayedFacts
.
Remove
(
fact
.
Id
);
displayedFacts
.
Remove
(
fact
.
Id
);
}
}
...
@@ -90,9 +119,83 @@ public void AnimateFact(Fact fact) {
...
@@ -90,9 +119,83 @@ public void AnimateFact(Fact fact) {
factIcon
.
GetComponentInChildren
<
ImageHintAnimation
>().
AnimationTrigger
();
factIcon
.
GetComponentInChildren
<
ImageHintAnimation
>().
AnimationTrigger
();
}
}
private
GameObject
CreateDisplay
(
Transform
transform
,
Fact
fact
)
#
region
Favorites
public
void
FavoritesFilterChanged
(
Toggle
t
)
{
{
var
spot
=
Instantiate
(
factSpotPrefab
,
factscreenContent
);
showOnlyFavorites
=
t
.
isOn
;
return
fact
.
instantiateDisplay
(
prefabDictionary
[
fact
.
GetType
()],
spot
.
transform
);
if
(!
showOnlyFavorites
)
// show all
displayedFacts
.
Values
.
ToList
().
ForEach
(
nFav
=>
nFav
.
transform
.
parent
.
gameObject
.
SetActive
(!
showOnlyFavorites
));
else
{
// hide not favorites
var
notFavorites
=
displayedFacts
.
Values
.
Where
(
go
=>
!
go
.
GetComponent
<
FactFavorisation
>().
IsFavorite
).
ToList
();
notFavorites
.
ForEach
(
nFav
=>
nFav
.
transform
.
parent
.
gameObject
.
SetActive
(
false
));
}
}
private
void
OnFavoriteChange
(
Fact
changedFact
,
bool
isFavourite
)
{
if
(!
showOnlyFavorites
)
return
;
var
id
=
changedFact
.
Id
;
if
(
displayedFacts
.
ContainsKey
(
id
))
displayedFacts
[
id
].
transform
.
parent
.
gameObject
.
SetActive
(
isFavourite
);
}
#
endregion
Favorites
#
region
Grouping
public
void
GroupingChanged
(
Toggle
t
)
{
showGrouped
=
t
.
isOn
;
List
<
Transform
>
vals
=
GetChildObjects
(
factscreenContent
.
transform
);
List
<
Transform
>
ordered
=
new
();
if
(
showGrouped
)
{
var
comparer
=
new
FactTypeComparer
();
ordered
=
vals
.
OrderBy
(
tr
=>
tr
.
GetComponentInChildren
<
FactWrapper
>().
fact
,
comparer
).
ToList
();
}
else
ordered
=
vals
.
OrderBy
(
tr
=>
displayedFacts
.
Keys
.
ToList
().
IndexOf
(
tr
.
GetComponentInChildren
<
FactWrapper
>().
fact
.
Id
)).
ToList
();
for
(
int
i
=
0
;
i
<
ordered
.
Count
;
i
++)
ordered
[
i
].
transform
.
SetSiblingIndex
(
i
);
}
private
int
GetIndexInSortedList
(
Fact
f
,
List
<
Fact
>
toCheck
)
{
var
index
=
toCheck
.
BinarySearch
(
f
,
new
FactTypeComparer
());
if
(
index
<
0
)
index
=
~
index
;
return
index
;
}
internal
class
FactTypeComparer
:
IComparer
<
Fact
>
{
/// <summary>
/// Compare two facts by type and label
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public
int
Compare
(
Fact
x
,
Fact
y
)
{
if
(
x
.
GetType
()
==
y
.
GetType
())
// same type: compare labels
return
string
.
Compare
(
x
.
Label
,
y
.
Label
);
else
// different types: compare type
return
string
.
Compare
(
x
.
GetType
().
ToString
(),
y
.
GetType
().
ToString
());
}
}
#
endregion
Grouping
#
region
Helper
private
static
List
<
Transform
>
GetChildObjects
(
Transform
parent
)
{
List
<
Transform
>
children
=
new
();
foreach
(
Transform
val
in
parent
)
children
.
Add
(
val
);
return
children
;
}
}
#
endregion
Helper
#
endregion
Implementation
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment