129 lines
4.5 KiB
C#
129 lines
4.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public static class PanelFactory
|
|
{
|
|
// panel basics config
|
|
private static Vector3 DialoguePanelPosition = new Vector3(0, 75, 0);
|
|
private static Vector2 DialoguePanelSize = new Vector2(800, 665);
|
|
private static Vector3 DialoguePanelScale = new Vector3(0.95f, 0.2f, 1);
|
|
|
|
// buttons config
|
|
private static Vector3 BaseButtonPosition = new Vector3(110, 0, 0);
|
|
private static Vector2 BaseButtonSize = new Vector2(150, 80);
|
|
private static Vector3 BaseButtonScale = new Vector3(1, 1, 1);
|
|
|
|
private static Vector3 AcceptButtonPosition = new Vector3(90, 270, 0);
|
|
private static Vector2 AcceptButtonSize = new Vector2(100, 80);
|
|
private static Vector3 AcceptButtonScale = new Vector3(1, 1, 1);
|
|
|
|
private static Vector3 RejectButtonPosition = new Vector3(105, 155, 0);
|
|
private static Vector2 RejectButtonSize = new Vector2(130, 80);
|
|
private static Vector3 RejectButtonScale = new Vector3(1, 1, 1);
|
|
|
|
const int BOTTOM_MARGIN = 15;
|
|
|
|
public static Panel BasePanel(string _header, DialogueModel _dialogueModel)
|
|
{
|
|
Panel panel;
|
|
|
|
// decide whic panel use later in the code
|
|
if (_dialogueModel.Buttons.ToArray().Length == 0)
|
|
panel = PanelFactory.TextPanel(_header, _dialogueModel.Sentence);
|
|
else
|
|
{
|
|
|
|
panel = new QuestionPanel();
|
|
|
|
|
|
panel.Header = _header;
|
|
panel.Content = _dialogueModel.Sentence;
|
|
|
|
|
|
panel.Scale = DialoguePanelScale;
|
|
panel.Size = new Vector2(DialoguePanelSize.x, 480 + ((BaseButtonSize.y + 30) * _dialogueModel.Buttons.ToArray().Length));
|
|
|
|
// y position: panel.Height/10 + margin (15)
|
|
panel.Position = new Vector2(DialoguePanelPosition.x, panel.Size.y / 10 + BOTTOM_MARGIN);
|
|
|
|
|
|
_dialogueModel.Buttons.Reverse();
|
|
|
|
foreach (var buttonModelWithIndex in _dialogueModel.Buttons.Select((value, index) => new { value, index }))
|
|
{
|
|
((QuestionPanel)panel).Answers.Add(
|
|
ButtonPanel(
|
|
new Vector2(BaseButtonPosition.x, BOTTOM_MARGIN + 40 + (30 + BaseButtonSize.y) * (buttonModelWithIndex.index + 1)),
|
|
BaseButtonSize,
|
|
BaseButtonScale,
|
|
buttonModelWithIndex.value
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
return panel;
|
|
}
|
|
|
|
public static Panel TextPanel(string _header, string _content) // panel wit "continue" button
|
|
{
|
|
Panel panel = new Panel();
|
|
|
|
panel.Header = _header;
|
|
panel.Content = _content;
|
|
|
|
panel.Scale = DialoguePanelScale;
|
|
panel.Size = DialoguePanelSize;
|
|
panel.Position = new Vector2(DialoguePanelPosition.x, panel.Size.y / 10 + BOTTOM_MARGIN);
|
|
|
|
|
|
return panel;
|
|
}
|
|
|
|
public static Panel QuestionPanel(string _header, string _content)
|
|
{
|
|
QuestionPanel panel = new QuestionPanel();
|
|
|
|
// set buttons
|
|
panel.Answers.Add(new ButtonPanelModel(PanelButtonEnum.Accept, AcceptButtonPosition, AcceptButtonSize, AcceptButtonScale));
|
|
panel.Answers.Add(new ButtonPanelModel(PanelButtonEnum.Reject, RejectButtonPosition, RejectButtonSize, RejectButtonScale));
|
|
|
|
panel.Header = _header;
|
|
panel.Content = _content;
|
|
|
|
panel.Position = DialoguePanelPosition;
|
|
panel.Size = DialoguePanelSize;
|
|
panel.Scale = DialoguePanelScale;
|
|
|
|
return panel;
|
|
}
|
|
|
|
// TODO some panel with more than two answres
|
|
public static Panel QuestionPanel(string _header, DialogueModel _dialogueModel )
|
|
{
|
|
QuestionPanel panel = new QuestionPanel();
|
|
|
|
// TODO to C-H-A-N-G-E ! ! !
|
|
panel.Answers.Add(new ButtonPanelModel(PanelButtonEnum.Accept, AcceptButtonPosition, AcceptButtonSize, AcceptButtonScale));
|
|
panel.Answers.Add(new ButtonPanelModel(PanelButtonEnum.Reject, RejectButtonPosition, RejectButtonSize, RejectButtonScale));
|
|
|
|
panel.Header = _header;
|
|
panel.Content = _dialogueModel.Sentence;
|
|
|
|
panel.Position = DialoguePanelPosition;
|
|
panel.Size = DialoguePanelSize;
|
|
panel.Scale = DialoguePanelScale;
|
|
|
|
return panel;
|
|
}
|
|
|
|
public static ButtonPanelModel ButtonPanel(Vector3 _position, Vector2 _size, Vector3 _scale, PanelButtonStepModel _buttonData)
|
|
{
|
|
return new ButtonPanelModel(_position, _size, _scale, _buttonData);
|
|
}
|
|
}
|