-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaOSATableAdapter.cs
More file actions
135 lines (119 loc) · 4.2 KB
/
LuaOSATableAdapter.cs
File metadata and controls
135 lines (119 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* * * * This bare-bones script was auto-generated * * * *
* The code commented with "/ * * /" demonstrates how data is retrieved and passed to the adapter, plus other common commands. You can remove/replace it once you've got the idea
* Complete it according to your specific use-case
* Consult the Example scripts if you get stuck, as they provide solutions to most common scenarios
*
* Main terms to understand:
* Model = class that contains the data associated with an item (title, content, icon etc.)
* Views Holder = class that contains references to your views (Text, Image, MonoBehavior, etc.)
*
* Default expected UI hiererchy:
* ...
* -Canvas
* ...
* -MyScrollViewAdapter
* -Viewport
* -Content
* -Scrollbar (Optional)
* -ItemPrefab (Optional)
*
* Note: If using Visual Studio and opening generated scripts for the first time, sometimes Intellisense (autocompletion)
* won't work. This is a well-known bug and the solution is here: https://developercommunity.visualstudio.com/content/problem/130597/unity-intellisense-not-working-after-creating-new-1.html (or google "unity intellisense not working new script")
*
*
* Please read the manual under "Assets/OSA/Docs", as it contains everything you need to know in order to get started, including FAQ
*/
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using Com.TheFallenGames.OSA.CustomAdapters.TableView;
using Com.TheFallenGames.OSA.CustomAdapters.TableView.Basic;
using Com.TheFallenGames.OSA.Core;
using Com.TheFallenGames.OSA.CustomAdapters.TableView.Extra;
using Com.TheFallenGames.OSA.CustomAdapters.TableView.Tuple;
// You should modify the namespace to your own or - if you're sure there won't ever be conflicts - remove it altogether
namespace Runtime
{
/// <summary>
/// Template demonstrating the use of a <see cref="TableAdapter{TParams, TTupleViewsHolder, THeaderTupleViewsHolder}"/>.
/// </summary>
public class LuaOSATableAdapter : TableAdapter<TableParams, LuaOSATupleViewsHolder, TupleViewsHolder>
{
List<string> _Indexes = new List<string>();
protected override void Start()
{
base.Start();
}
public void ReloadData(List<IColumnInfo> headers, ITuple[] tuples, List<string> indexes, bool columnSortingSupported = false)
{
Columns = new BasicTableColumns(headers);
Tuples = new BasicTableData(Columns, tuples, columnSortingSupported);
_Indexes = indexes;
ResetTableWithCurrentData();
}
protected override void UpdateViewsHolder(LuaOSATupleViewsHolder newOrRecycled)
{
var tuple = Tuples.GetTuple(newOrRecycled.ItemIndex);
newOrRecycled.UpdateViews(tuple, Columns);
if (_Indexes.Count > 0 && newOrRecycled.ItemIndex < _Indexes.Count) {
newOrRecycled.UpdateIndex(_Indexes[newOrRecycled.ItemIndex]);
}
}
}
public class LuaOSATableHelper
{
public static BasicTuple CreateTupleWithEmptyValues(int length)
{
return TableViewUtil.CreateTupleWithEmptyValues<BasicTuple>(length);
}
}
public class LuaOSATupleViewsHolder : TupleViewsHolder
{
public ITupleAdapter Adapter { get; private set; }
public override void CollectViews()
{
base.CollectViews();
}
public virtual void UpdateViews(ITuple tuple, ITableColumns columns)
{
base.UpdateViews(tuple, columns);
}
public void UpdateIndex(string newIndex)
{
if (_IndexText != null) {
_IndexText.text = newIndex;
}
}
}
public class LuaOSATableHeader : IColumnInfo
{
public string Name
{
get { return _Name; }
set
{
if (_Name == value)
return;
_Name = value;
ReconstructDisplayName();
}
}
public string DisplayName { get; set; }
public TableValueType ValueType { get; private set; }
public Type EnumValueType { get; private set; }
string _Name;
public LuaOSATableHeader(string name, TableValueType valueType, Type enumValueType = null)
{
ValueType = valueType;
EnumValueType = enumValueType;
// Setting it last, so the display name will be reconstructed using the other properties
Name = name;
}
void ReconstructDisplayName()
{
DisplayName = _Name;
}
}
}