last update
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using YandexQuest.Models;
|
||||
using Zenject;
|
||||
|
||||
@@ -10,15 +11,33 @@ public class AdminPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text _city;
|
||||
[SerializeField] private TMP_InputField _key;
|
||||
[Space]
|
||||
[SerializeField] private UIMenu _tagsDescMenu;
|
||||
[SerializeField] private UIMenu _winnersTableMenu;
|
||||
|
||||
[Inject] private readonly NetworkService _networkService;
|
||||
[Inject] private readonly ClientDataService _clientDataService;
|
||||
|
||||
private UIMenu _menu;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_menu = GetComponent<UIMenu>();
|
||||
}
|
||||
|
||||
public void ShowTagsDescription()
|
||||
{
|
||||
_menu.SetNextMenu(_tagsDescMenu);
|
||||
_menu.ShowNextMenu();
|
||||
}
|
||||
|
||||
public async void Initialize(Cities city)
|
||||
{
|
||||
_city.text = _clientDataService.citiesTranslation[city];
|
||||
var result = await _networkService.GetAsync<int>($"auth/secretcode/{(int)city}");
|
||||
_key.text = result.responseData.ToString();
|
||||
|
||||
_clientDataService.city = (int)city;
|
||||
}
|
||||
|
||||
public void CopyToClipboard() => GUIUtility.systemCopyBuffer = _key.text;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Authorization : MonoBehaviour
|
||||
_menu = GetComponent<UIMenu>();
|
||||
_adminPanel = _adminMenu.GetComponent<AdminPanel>();
|
||||
|
||||
if(_clientDataService.data != null)
|
||||
if (_clientDataService.data != null)
|
||||
{
|
||||
Debug.LogWarning($"данные клианта {_clientDataService.data.id} загружены: город - {(Cities)_clientDataService.data.city}, найдено тэгов - {_clientDataService.data.games.Count}");
|
||||
// UniTask.Void(async ()=>
|
||||
@@ -52,7 +52,7 @@ public class Authorization : MonoBehaviour
|
||||
|
||||
_codeInputField.onValueChanged.AddListener(stringValue =>
|
||||
{
|
||||
if(stringValue.Length != 6)
|
||||
if (stringValue.Length != 6)
|
||||
{
|
||||
_codeAcceptButton.interactable = false;
|
||||
}
|
||||
@@ -72,9 +72,8 @@ public class Authorization : MonoBehaviour
|
||||
{
|
||||
CityUniqueCode cityUniqueCode = null;
|
||||
var resultAdmin = await _networkService.GetAsync<CityUniqueCode>($"auth/admin/{inputFieldText}");
|
||||
cityUniqueCode = resultAdmin.responseData;
|
||||
|
||||
if(resultAdmin.responseCode == 0)
|
||||
if (resultAdmin.responseCode == 0)
|
||||
{
|
||||
var message = "Нет соединения с сервером";
|
||||
Debug.LogError(message);
|
||||
@@ -85,18 +84,18 @@ public class Authorization : MonoBehaviour
|
||||
Debug.LogWarning("такого админа нет в базе. ищем город...");
|
||||
var result = await _networkService.GetAsync<Client>($"auth/{inputFieldText}");
|
||||
|
||||
if(result.responseCode == 404)
|
||||
if (result.responseCode == 404)
|
||||
{
|
||||
Debug.LogError(result.responseText);
|
||||
_inputField.ShowErrorAsync(result.responseText).Forget();
|
||||
}
|
||||
else if(result.responseCode == 0)
|
||||
else if (result.responseCode == 0)
|
||||
{
|
||||
var message = "Нет соединения с сервером";
|
||||
Debug.LogError(message);
|
||||
_inputField.ShowErrorAsync(message).Forget();
|
||||
}
|
||||
else if(result.responseCode == 200)
|
||||
else if (result.responseCode == 200)
|
||||
{
|
||||
_clientDataService.data = result.responseData;
|
||||
Debug.Log(result.responseData.city.ToString());
|
||||
@@ -104,9 +103,12 @@ public class Authorization : MonoBehaviour
|
||||
_menu.ShowNextMenu();
|
||||
}
|
||||
}
|
||||
else if(resultAdmin.responseCode == 200)
|
||||
else if (resultAdmin.responseCode == 200)
|
||||
{
|
||||
cityUniqueCode = resultAdmin.responseData;
|
||||
|
||||
_adminPanel.Initialize(resultAdmin.responseData.cityEnum);
|
||||
_clientDataService.city = (int)resultAdmin.responseData.cityEnum;
|
||||
|
||||
_menu.SetNextMenu(_adminMenu);
|
||||
_menu.ShowNextMenu();
|
||||
|
||||
@@ -73,8 +73,8 @@ namespace YandexQuest.Models
|
||||
public class Tag
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string descrition { get; set; }
|
||||
public Games game { get; set; }
|
||||
public string description { get; set; }
|
||||
public Cities city { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,7 @@ public class AppInstaller : MonoInstaller
|
||||
Container.Bind<NetworkService>().AsSingle().NonLazy();
|
||||
Container.Bind<ClientDataService>().AsSingle();
|
||||
Container.Bind<SceneLoadingService>().AsSingle();
|
||||
|
||||
Container.Bind<TagDescriptionsPanel>().FromComponentInHierarchy().AsSingle();
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,13 @@ public class ClientDataService
|
||||
}
|
||||
}
|
||||
|
||||
public int position
|
||||
public int city
|
||||
{
|
||||
get => PlayerPrefs.GetInt("city", -1);
|
||||
set => PlayerPrefs.SetInt("city", value);
|
||||
}
|
||||
|
||||
public int topPosition
|
||||
{
|
||||
get => PlayerPrefs.GetInt("position", 0);
|
||||
set => PlayerPrefs.SetInt("position", value);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class NetworkService
|
||||
catch { }
|
||||
|
||||
responseStruct.responseCode = getRequest.responseCode;
|
||||
if(getRequest.responseCode != 200)
|
||||
if (getRequest.responseCode != 200)
|
||||
{
|
||||
responseStruct.responseText = getRequest.downloadHandler.text;
|
||||
return responseStruct;
|
||||
@@ -50,7 +50,7 @@ public class NetworkService
|
||||
|
||||
return responseStruct;
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStruct.responseCode = -1;
|
||||
responseStruct.responseText = ex.Message;
|
||||
@@ -86,7 +86,7 @@ public class NetworkService
|
||||
catch { }
|
||||
|
||||
responseStruct.responseCode = getRequest.responseCode;
|
||||
if(getRequest.responseCode != 200)
|
||||
if (getRequest.responseCode != 200)
|
||||
{
|
||||
responseStruct.responseText = getRequest.downloadHandler.text;
|
||||
return responseStruct;
|
||||
@@ -98,7 +98,7 @@ public class NetworkService
|
||||
responseStruct.responseData = result;
|
||||
return responseStruct;
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStruct.responseCode = -1;
|
||||
responseStruct.responseText = ex.Message;
|
||||
@@ -122,8 +122,8 @@ public class NetworkService
|
||||
}
|
||||
|
||||
using var getRequest = UnityWebRequest.Get(_apiUrl + stringBuilder.ToString());
|
||||
if(headers != null)
|
||||
foreach(var header in headers)
|
||||
if (headers != null)
|
||||
foreach (var header in headers)
|
||||
getRequest.SetRequestHeader(header.Key, header.Value);
|
||||
|
||||
getRequest.SetRequestHeader("Content-type", "application/json");
|
||||
@@ -136,7 +136,7 @@ public class NetworkService
|
||||
catch { }
|
||||
|
||||
responseStruct.responseCode = getRequest.responseCode;
|
||||
if(getRequest.responseCode != 200)
|
||||
if (getRequest.responseCode != 200)
|
||||
{
|
||||
responseStruct.responseText = getRequest.downloadHandler.text;
|
||||
return responseStruct;
|
||||
@@ -149,7 +149,7 @@ public class NetworkService
|
||||
|
||||
return responseStruct;
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStruct.responseCode = -1;
|
||||
responseStruct.responseText = ex.Message;
|
||||
@@ -158,21 +158,22 @@ public class NetworkService
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask PostAsync<TValue> (string requestString, TValue data, Dictionary<string, string> headers = null)
|
||||
{
|
||||
public async UniTask PostAsync<TValue>(string requestString, TValue data, Dictionary<string, string> headers = null)
|
||||
{
|
||||
string sendingData = JsonConvert.SerializeObject(data);
|
||||
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
|
||||
if(headers != null)
|
||||
using var postRequest = new UnityWebRequest(_apiUrl + requestString, "POST");
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
||||
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
if (headers != null)
|
||||
{
|
||||
foreach(var header in headers)
|
||||
foreach (var header in headers)
|
||||
postRequest.SetRequestHeader(header.Key, header.Value);
|
||||
}
|
||||
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
@@ -182,17 +183,18 @@ public class NetworkService
|
||||
catch { }
|
||||
}
|
||||
|
||||
public async UniTask<Response<TResponseValue>> PostAsync<TSendingValue, TResponseValue> (string requestString, TSendingValue data)
|
||||
public async UniTask<Response<TResponseValue>> PostAsync<TSendingValue, TResponseValue>(string requestString, TSendingValue data)
|
||||
{
|
||||
Response<TResponseValue> responseStruct = new Response<TResponseValue>();
|
||||
|
||||
string sendingData = JsonConvert.SerializeObject(data);
|
||||
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
using var postRequest = new UnityWebRequest(_apiUrl + requestString, "POST");
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
||||
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
@@ -202,7 +204,7 @@ public class NetworkService
|
||||
catch { }
|
||||
|
||||
responseStruct.responseCode = postRequest.responseCode;
|
||||
if(postRequest.responseCode != 200)
|
||||
if (postRequest.responseCode != 200)
|
||||
{
|
||||
responseStruct.responseText = postRequest.downloadHandler.text;
|
||||
return responseStruct;
|
||||
@@ -215,7 +217,7 @@ public class NetworkService
|
||||
|
||||
return responseStruct;
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStruct.responseCode = -1;
|
||||
responseStruct.responseText = ex.Message;
|
||||
|
||||
@@ -1,12 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Cysharp.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using YandexQuest.Models;
|
||||
using Zenject;
|
||||
|
||||
public class DescriptionCard : MonoBehaviour
|
||||
{
|
||||
[Inject] private readonly NetworkService _networkService;
|
||||
[Inject] private readonly ClientDataService _clientDataService;
|
||||
private TagDescriptionsPanel _tagDescPanel;
|
||||
|
||||
[SerializeField] public Games game;
|
||||
[SerializeField] private TMP_InputField _descriptionField;
|
||||
[SerializeField] private Button _acceptChangesButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_tagDescPanel = FindObjectOfType<TagDescriptionsPanel>();
|
||||
_tagDescPanel.cards.Add(this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_descriptionField.text = "Для данной QR-метки ещё нет описания...";
|
||||
|
||||
_acceptChangesButton.onClick
|
||||
.AddListener(() => SetTagDescription().Forget());
|
||||
}
|
||||
|
||||
public void Init(Tag tag)
|
||||
{
|
||||
_descriptionField.text = tag.description;
|
||||
}
|
||||
|
||||
private async UniTaskVoid SetTagDescription()
|
||||
{
|
||||
Tag tag = new Tag()
|
||||
{
|
||||
id = string.Empty,
|
||||
game = game,
|
||||
description = _descriptionField.text,
|
||||
city = (Cities)_clientDataService.city
|
||||
};
|
||||
|
||||
await _networkService.PostAsync<Tag>("game/tags/add", tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
using YandexQuest.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
public class TagDescriptionsPanel : MonoBehaviour
|
||||
{
|
||||
public List<DescriptionCard> cards { get; set; } = new List<DescriptionCard>();
|
||||
|
||||
[Inject] private readonly NetworkService _networkService;
|
||||
[Inject] private readonly ClientDataService _clientDataService;
|
||||
|
||||
private List<Tag> _tags;
|
||||
|
||||
private async UniTaskVoid OnEnable()
|
||||
{
|
||||
var result = await _networkService
|
||||
.GetAsync<List<Tag>>($"game/tags/{(int)_clientDataService.city}");
|
||||
|
||||
if (result.responseData != null)
|
||||
{
|
||||
_tags = result.responseData;
|
||||
|
||||
foreach (var card in cards)
|
||||
{
|
||||
var data = _tags.Find(x => x.game == card.game);
|
||||
if (data != null) card.Init(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1acb4224a2cc1884295feba5466f5da0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user