// --- \TNManager.hs --- const int TOASTNOTICE_TYPE_INFO_ID = 00; const int TOASTNOTICE_TYPE_WARNING_ID = 10; const int TOASTNOTICE_TYPE_ERROR_ID = 20; // トースト通知システム // コンポーネントとして独立すべし。 component TNManager{ const string TOASTNOTICE_LAYER_NAME = "ToastNotice"; const int _maxNotice = 5; list _noticeActorList; // 溢れてる時用 list _stackToastNoticeList; bool _isWorldLoadEnd; // 通知を出した回数 int _noticeCounter; public TNManager(){ if(_noticeActorList === null){ _noticeActorList = new list(); } if(_stackToastNoticeList === null){ _stackToastNoticeList = new list(); } _isWorldLoadEnd = false; _noticeCounter = 0; hsAddEventListener("send-notify-message", AddNoticeFromJS); } private bool WorldLoadChecker(){ LayerBundle layer = hsLayerGet(TOASTNOTICE_LAYER_NAME); return IsGetLayerBundle(layer); } private void Initialize(){ LayerBundle layer = hsLayerGet(TOASTNOTICE_LAYER_NAME); layer.SetShow(true); } public void Update(){ // ワールドの初期読み込みチェック if(_isWorldLoadEnd == false){ if(WorldLoadChecker()){ Initialize(); _isWorldLoadEnd = true; } }else{ for(int i = 0; i < _noticeActorList.Count(); i++){ _noticeActorList[i].Update(); // 通知アクションが終了した時 if(_noticeActorList[i].IsEndNoticeAction()){ _noticeActorList[i].OnDelete(); _noticeActorList.RemoveAt(i); // 後ろに控えている通知がある場合 if(_stackToastNoticeList.IsEmpty() == false){ // 一番最初に追加されたものを追加する。 _noticeActorList.Add(_stackToastNoticeList[0]); _stackToastNoticeList.RemoveAt(0); } if(_noticeActorList.IsEmpty()){ break; } --i; RefleshNoticeActionViewID(); } } } } // Canvasの読み込み完了チェッカー private bool IsGetLayerBundle(LayerBundle layerbundle){ bool isNull = layerbundle.ToString() == "LayerBundle(portrait: null, landscape: null)"; bool isNonLoded = layerbundle.ToString() == "LayerBundle(portrait: , landscape: )"; return (isNull == false) && (isNonLoded == false); } void AddNoticeFromJS(string data){ Json noticeJson = hsLoadJson(data); // 種類 int noticeTypeID = TOASTNOTICE_TYPE_INFO_ID; noticeJson.FindValueInt("noticeTypeID", noticeTypeID); // 通知メッセージ string noticeText = ""; noticeJson.FindValueString("message", noticeText); // 表示時間 float viewTime = 5; noticeJson.FindValueFloat("viewTime", viewTime); // 通知識別キー string identifyKey = "default"; noticeJson.FindValueString("identifyKey", identifyKey); // 通知識別キー string optionData = ""; noticeJson.FindValueString("optionData", optionData); AddNotice(noticeTypeID, noticeText, viewTime, identifyKey, optionData); } // 通知を追加する public void AddNotice(int noticeTypeID, string noticeText, float displayTime, string identifyKey, string optionData){ TNActor notice = new TNActor(); notice.Initialize(_noticeCounter, TOASTNOTICE_LAYER_NAME, noticeTypeID, noticeText, identifyKey, optionData); notice.SetDisplayTime(displayTime); if(_noticeActorList === null){ _noticeActorList = new list(); } if(_stackToastNoticeList === null){ _stackToastNoticeList = new list(); } if(_noticeActorList.Count() < _maxNotice){ _noticeActorList.Add(notice); RefleshNoticeActionViewID(); }else{ _stackToastNoticeList.Add(notice); } _noticeCounter ++; } private void RefleshNoticeActionViewID(){ if(_noticeActorList.IsEmpty()){ return; } int viewSortId = 0; int lastIndex = _noticeActorList.Count() - 1; for(int i = lastIndex; i >= 0 ; i--){ _noticeActorList[i].ChangeNoticeViewID(viewSortId); viewSortId ++; } } // 画面サイズが変わった場合 public void OnResize(int _width, int _height){ } public void OnClickedButton(string _layerName, string _buttonName){ if(_layerName != TOASTNOTICE_LAYER_NAME){ return ;} string noticeBaseGUITempName = "NoticeBase_button_"; if(_buttonName.IndexOf(noticeBaseGUITempName) == -1){ return; } int uuidArea = _buttonName.Length() - noticeBaseGUITempName.Length(); int noticeUUID = _buttonName.SubString(noticeBaseGUITempName.Length(), uuidArea).ToInt(); NoticeForceQuit(noticeUUID); } private void NoticeForceQuit(int noticeID){ for(int i = 0; i < _noticeActorList.Count(); i++){ if(noticeID == _noticeActorList[i].GetNoticeUUID()){ _noticeActorList[i].NoticeForceQuit(); } } } } // --- \Class\GUIAnimaitor.hs --- // --- \GAActor.hs --- /// アニメーションタグ const int ANIM_TAG_MISSING = -1; const int ANIM_TAG_SETPOS_X = 00; const int ANIM_TAG_SETPOS_Y = 01; const int ANIM_TAG_MOVE_X = 10; const int ANIM_TAG_MOVE_Y = 11; const int ANIM_TAG_SCARE_X = 20; const int ANIM_TAG_SCARE_Y = 21; const int ANIM_TAG_ROTATE = 30; class GAActor{ string _layerName; string _guiName; bool _usePortrait; Layer _actionLayer; list _guiAnimList; HS2DI _guiFromPos; HS2DI _guiFromSize; int _easeType; float _timeCounter; public GAActor() { _layerName = ""; _guiName = ""; _usePortrait = false; _actionLayer = new Layer(); _guiAnimList = new list(); _guiFromPos = new HS2DI(); _guiFromSize = new HS2DI(); _easeType = 0; _timeCounter = 0; } public void Initialize(string layerName, string guiName, int easeTypeID, bool usePortraitFlag){ _timeCounter = 0; _layerName = layerName; _guiName = guiName; _easeType = easeTypeID; _usePortrait = usePortraitFlag; _actionLayer = new Layer(); if(usePortraitFlag){ _actionLayer = hsLayerGetPortrait(_layerName); }else{ _actionLayer = hsLayerGetLandscape(_layerName); } float posX = 0; float posY = 0; _actionLayer.GetGUIPos(guiName, posX, posY); float sizeX = 0; float sizeY = 0; _actionLayer.GetGUISize(guiName, sizeX, sizeY); HS2DI pos = MakeHS2DI(posX, posY); HS2DI size = MakeHS2DI(sizeX, sizeY); SetGUITransform(pos, size); } public void SetGUITransform(HS2DI pos, HS2DI size){ _guiFromPos = pos; _guiFromSize = size; } public void Update() { ApplyTransform(); float deltaTime = hsSystemGetDeltaTime(); _timeCounter += deltaTime; for(int i = _guiAnimList.Count() - 1; i > -1; i--){ _guiAnimList[i].Update(deltaTime); if(_guiAnimList[i].IsFinished()){ _guiAnimList.RemoveAt(i); } } } /// NOTICE //// /// もし、新しいアニメーション処理を加える場合は、 /// この関数(ApplyTransform)のswitch文に分岐処理を追加実装する事! private void ApplyTransform(){ float defPosX = _guiFromPos.x(); float defPosY = _guiFromPos.y(); float defSizeX = _guiFromSize.x(); float defSizeY = _guiFromSize.y(); bool moveFlag = false; bool scaleFlag = false; for(int i = 0; i < _guiAnimList.Count(); i++){ float animVal = _guiAnimList[i].GetNowAnimVec(_easeType); switch(_guiAnimList[i].GetAnimTag()){ case ANIM_TAG_SETPOS_X: defPosX = animVal; moveFlag = true; break; case ANIM_TAG_SETPOS_Y: defPosY = animVal; moveFlag = true; break; case ANIM_TAG_MOVE_X: defPosX += animVal; moveFlag = true; break; case ANIM_TAG_MOVE_Y: defPosY += animVal; moveFlag = true; break; case ANIM_TAG_SCARE_X: defSizeX += animVal; scaleFlag = true; break; case ANIM_TAG_SCARE_Y: defSizeY += animVal; scaleFlag = true; break; default: break; } } if(moveFlag){ _actionLayer.SetGUIPos(_guiName, defPosX, defPosY); } if(scaleFlag){ _actionLayer.SetGUISize(_guiName, defSizeX, defSizeY); } } // 座標の更新 public GAActor SetPos(HS2DI pos){ GAAnimation posX = new GAAnimation(); GAAnimation posY = new GAAnimation(); posX.SetAnimTag(ANIM_TAG_SETPOS_X); posX.SetAnimVec(pos.x()); posX.SetDurationTime(0.001); posY.SetAnimTag(ANIM_TAG_SETPOS_Y); posY.SetAnimVec(pos.y()); posY.SetDurationTime(0.001); _guiAnimList.Add(posX); _guiAnimList.Add(posY); return this; } // 特定座標への移動 public GAActor MovePos(HS2DI toPos, float durationTime) { GAAnimation moveX = new GAAnimation(); GAAnimation moveY = new GAAnimation(); moveX.SetAnimTag(ANIM_TAG_MOVE_X); moveX.SetAnimVec(toPos.x() - _guiFromPos.x()); moveX.SetDurationTime(durationTime); moveY.SetAnimTag(ANIM_TAG_MOVE_Y); moveY.SetAnimVec(toPos.y() - _guiFromPos.y()); moveY.SetDurationTime(durationTime); _guiAnimList.Add(moveX); _guiAnimList.Add(moveY); return this; } // 相対座標への移動 public GAActor MoveVec(HS2DI toPos, float durationTime) { GAAnimation moveX = new GAAnimation(); GAAnimation moveY = new GAAnimation(); moveX.SetAnimTag(ANIM_TAG_MOVE_X); moveX.SetAnimVec(toPos.x()); moveX.SetDurationTime(durationTime); moveY.SetAnimTag(ANIM_TAG_MOVE_Y); moveY.SetAnimVec(toPos.y()); moveY.SetDurationTime(durationTime); _guiAnimList.Add(moveX); _guiAnimList.Add(moveY); return this; } public GAActor Scale(HS2DI toSize, float durationTime) { GAAnimation scaleX = new GAAnimation(); GAAnimation scaleY = new GAAnimation(); scaleX.SetAnimTag(ANIM_TAG_SCARE_X); scaleX.SetAnimVec(toSize.x() - _guiFromSize.x()); scaleX.SetDurationTime(durationTime); scaleY.SetAnimTag(ANIM_TAG_SCARE_Y); scaleY.SetAnimVec(toSize.y() - _guiFromSize.y()); scaleY.SetDurationTime(durationTime); _guiAnimList.Add(scaleX); _guiAnimList.Add(scaleY); return this; } // 何故かGCで削除される...とりあえずインターフェースとして残しておく public GAActor SetEase(int easeType){ _easeType = easeType; return this; } public bool IsFinished() { return _guiAnimList.Count() <= 0; } private HS2DI MakeHS2DI(int x, int y){ HS2DI hs2di = new HS2DI(); hs2di.SetXY(x, y); return hs2di; } } // --- \GAAnimation.hs --- // 移動、回転、スケールの秒数経過による変化量だけ計算する存在 // animTagでどこに対応しているのかを識別させる class GAAnimation { GAEasing _easingLib; int _animTag; float _animVec; float _durationTime; float _animSpeed; float _deltaTimeCacher; public GAAnimation() { _easingLib = new GAEasing(); _animTag = ANIM_TAG_MISSING; _animVec = 0; _durationTime = 0; _animSpeed = 0; _deltaTimeCacher = 0; } // アニメーションのタイプ public void SetAnimTag(int animTag){ _animTag = animTag; } public int GetAnimTag(){ return _animTag; } // アニメーションの移動量 public void SetAnimVec(float animVec){ _animVec = animVec; } // 所要時間 public void SetDurationTime(float durationTime){ _durationTime = durationTime; _animSpeed = 1 / durationTime; } public void Update(float deltaTime) { _deltaTimeCacher += deltaTime; } public bool IsFinished(){ return _deltaTimeCacher >= _durationTime; } public float GetNowAnimVec(int easeType){ if(_animTag == ANIM_TAG_SETPOS_X){ return _animVec; } if(_animTag == ANIM_TAG_SETPOS_Y){ return _animVec; } float time = _deltaTimeCacher * _animSpeed; float easeVal = _easingLib.GetEasing(easeType, time); return _animVec * easeVal; } private float GetMin(float comparisonA, float comparisonB){ float minVal = comparisonA; if(comparisonA > comparisonB){ minVal = comparisonB; } return minVal; } } // --- \GAEasing.hs --- const int EASING_TYPE_LINER_ID = 00; const int EASING_TYPE_EASEINOUTBACK_ID = 01; const int EASING_TYPE_EASEOUTCIRC_ID = 02; const int EASING_TYPE_EASEOUTQUINT_ID = 03; // イージング関数をまとめてる場所 // easeTypeに対応するイージング関数を起動し、time(0~1)で変化量を返す class GAEasing{ public GAEasing(){ } public float GetEasing(int easeType, float time){ if(time > 1){ time = 1; } if(time < 0){ time = 0; } float easeVal = 0; switch(easeType){ case EASING_TYPE_LINER_ID: easeVal = time; break; case EASING_TYPE_EASEINOUTBACK_ID: easeVal = EaseInOutBack(time); break; case EASING_TYPE_EASEOUTCIRC_ID: easeVal = EaseOutCirc(time); break; case EASING_TYPE_EASEOUTQUINT_ID: easeVal = EaseOutQuint(time); break; default: break; } return easeVal; } public float EaseInOutBack(float _time){ float c1 = 1.70158; float c2 = c1 * 1.525; float val = (MathPow(2 * _time - 2, 2) * ((c2 + 1) * (_time * 2 - 2) + c2) + 2) / 2; if(_time < 0.5){ val = (MathPow(2 * _time, 2) * ((c2 + 1) * 2 * _time - c2)) / 2; } return val; } public float EaseOutCirc(float _time){ return hsMathSqrt(1 - MathPow(_time - 1, 2)); } public float EaseOutQuint(float _time){ return 1 - MathPow(1 - _time, 5); } private float MathPow(float _bace, float _exponent){ float operationResult = _bace; int i; for(i = 1; i < _exponent; i++){ operationResult *= _bace; } return operationResult; } } // --- \GAManager.hs --- // AddAnimation(string layerName, string guiName, int easeTypeID)からメソッドチェイン式で // GAActorのアニメーションを登録する事が出来ます。 // 使用するには、この機能をまとめたHSファイル1枚があるはずです。それをjsonのScripts[]に登録してください。 class GAManager{ list _guiActorList; public GAManager(){ _guiActorList = new list(); } public void Update(){ for(int i = _guiActorList.Count() - 1; i > -1; i--){ _guiActorList[i].Update(); if(_guiActorList[i].IsFinished()){ _guiActorList.RemoveAt(i); } } } public GAActor AddAnimation(string layerName, string guiName, int easeTypeID, bool usePortraitFlag){ GAActor newActor = new GAActor(); newActor.Initialize(layerName, guiName, easeTypeID, usePortraitFlag); _guiActorList.Add(newActor); return newActor; } } // --- \Class\TNActionStatus.hs --- const int TOASTNOTICE_ACTION_STATE_ID_START = 00; const int TOASTNOTICE_ACTION_STATE_ID_APPEAR = 10; const int TOASTNOTICE_ACTION_STATE_ID_DISPLAY = 20; const int TOASTNOTICE_ACTION_STATE_ID_DISAPPEAR = 30; const int TOASTNOTICE_ACTION_STATE_ID_END = 40; class TNActionStatus{ int _currentState; float _timeCounter; public TNActionStatus(){ _currentState = TOASTNOTICE_ACTION_STATE_ID_START; _timeCounter = 0; } public void SetActionState(int actionStateID){ if(_currentState == actionStateID){ return; } _currentState = actionStateID; _timeCounter = 0; } public int GetCurrentState(){ return _currentState; } public float GetCurrentStateTime(){ return _timeCounter; } public void Update(){ _timeCounter += hsSystemGetDeltaTime(); } } // --- \Class\TNActor.hs --- class TNActor{ const string TOASTNOTICE_GUI_NAME_BASE = "NoticeBase_button"; const string TOASTNOTICE_GUI_NAME_ICON = "NoticeIcon_image"; const string TOASTNOTICE_GUI_NAME_NOTICETYPE = "NoticeType_text"; const string TOASTNOTICE_GUI_NAME_NOTICETEXT = "NoticeText_text"; const string TOASTNOTICE_GUI_NAME_NOTICETIMER = "NoticeViewTimeBar_image"; const string TOASTNOTICE_GUI_NAME_NOTICETIMER_BASE = "NoticeViewTimeBar_Base_image"; const float NOTICE_APPER_ANIM_TIME = 0.5f; const float NOTICE_DISAPPER_ANIM_TIME = 0.5f; const float NOTICE_BASE_GUI_DEFAULT_POS_HEIGIHT = 85; const float NOTICE_BASE_GUI_DEFAULT_POS_HEIGIHT_PORTRAIT = 95; const float NOTICE_BASE_GUI_DEFAULT_SIZE_HEIGHT = 100; const bool USE_PORTRAIT = true; const bool USE_LANDSCAPE = false; string _layerName; // 識別番号(GUI内部処理用) int _noticeUUID; // ユーザー向け識別キー(任意でつけれるコード) string _noticeIdentifyKey; // ユーザー向け識別キー(任意でつけれるコード) string _optionData; TNActionStatus _actionStatus; Layer _landscapeLayer; Layer _portraitLayer; list _guiNameList; // 通知する種別ID int _noticeTypeID; // 通知する文章 string _noticeText; // 表示時間 float _displayTime; GAManager _guiAnimator; bool _isClicked; public TNActor(){ _layerName = ""; _noticeUUID = -1; _noticeIdentifyKey = ""; _optionData = ""; _actionStatus = new TNActionStatus(); _landscapeLayer = new Layer(); _portraitLayer = new Layer(); _guiNameList = new list(); _noticeTypeID = -1; _noticeText = "noticeText"; _displayTime = 5; _guiAnimator = new GAManager(); _isClicked = false; } public TNActor Initialize(int uuid, string layerName, int noticeTypeID, string noticeText, string identifyKey, string optionData){ _noticeUUID = uuid; _noticeIdentifyKey = identifyKey; _noticeTypeID = noticeTypeID; _noticeText = noticeText; _optionData = optionData; _isClicked = false; _layerName = layerName; _landscapeLayer = hsLayerGetLandscape(layerName); _portraitLayer = hsLayerGetPortrait(layerName); string extendID = "_%d" % uuid; _guiNameList = new list(); _guiNameList.Add(TOASTNOTICE_GUI_NAME_BASE + extendID); _guiNameList.Add(TOASTNOTICE_GUI_NAME_ICON + extendID); _guiNameList.Add(TOASTNOTICE_GUI_NAME_NOTICETYPE + extendID); _guiNameList.Add(TOASTNOTICE_GUI_NAME_NOTICETEXT + extendID); _guiNameList.Add(TOASTNOTICE_GUI_NAME_NOTICETIMER + extendID); _guiNameList.Add(TOASTNOTICE_GUI_NAME_NOTICETIMER_BASE + extendID); CreateToastGUI(noticeTypeID, noticeText); return this; } // トーストGUIを生成 private void CreateToastGUI(int noticeTypeID, string noticeText){ TNGUIGenerator guiGenerator = new TNGUIGenerator(); int baseIndex = 0; guiGenerator.CreteBase(_layerName, _guiNameList[baseIndex]); int iconIndex = 1; guiGenerator.CreteIcon(_layerName, _guiNameList[iconIndex], noticeTypeID); int noticeTypeText = 2; guiGenerator.CreteNoticeTypeText(_layerName, _guiNameList[noticeTypeText], noticeTypeID); int noticeTextIndex = 3; guiGenerator.CreteNoticeText(_layerName, _guiNameList[noticeTextIndex], noticeText); int viewTimeSeekBarBase = 4; guiGenerator.CreteViewTimerBase(_layerName, _guiNameList[viewTimeSeekBarBase]); int viewTimeSeekBar = 5; guiGenerator.CreteViewTimer(_layerName, _guiNameList[viewTimeSeekBar]); } public int GetNoticeUUID(){ return _noticeUUID; } public TNActor SetDisplayTime(float displayTime){ if(displayTime < 0.01) { displayTime = 0.01; } _displayTime = displayTime; return this; } public void Update(){ _guiAnimator.Update(); GUIPosReflesh(); _actionStatus.Update(); int postState = DitectState(); if(postState != _actionStatus.GetCurrentState()){ ChangeActionState(postState); } } private int DitectState(){ int postState = _actionStatus.GetCurrentState(); switch(_actionStatus.GetCurrentState()){ case TOASTNOTICE_ACTION_STATE_ID_START: postState = TOASTNOTICE_ACTION_STATE_ID_APPEAR; break; case TOASTNOTICE_ACTION_STATE_ID_APPEAR: if(_actionStatus.GetCurrentStateTime() >= NOTICE_APPER_ANIM_TIME){ postState = TOASTNOTICE_ACTION_STATE_ID_DISPLAY; } break; case TOASTNOTICE_ACTION_STATE_ID_DISPLAY: if(_actionStatus.GetCurrentStateTime() >= _displayTime){ postState = TOASTNOTICE_ACTION_STATE_ID_DISAPPEAR; } break; case TOASTNOTICE_ACTION_STATE_ID_DISAPPEAR: if(_actionStatus.GetCurrentStateTime() >= NOTICE_DISAPPER_ANIM_TIME){ postState = TOASTNOTICE_ACTION_STATE_ID_END; } break; case TOASTNOTICE_ACTION_STATE_ID_END: break; default: break; } return postState; } private void ChangeActionState(int stateID){ _actionStatus.SetActionState(stateID); switch(_actionStatus.GetCurrentState()){ case TOASTNOTICE_ACTION_STATE_ID_START: break; case TOASTNOTICE_ACTION_STATE_ID_APPEAR: HS2DI laAppearAnim = MakeHS2DI(-256, 0); _guiAnimator.AddAnimation(_layerName, _guiNameList[0], EASING_TYPE_EASEOUTCIRC_ID, USE_LANDSCAPE).MoveVec(laAppearAnim, NOTICE_APPER_ANIM_TIME); HS2DI poAppearAnim = MakeHS2DI(-512, 0); _guiAnimator.AddAnimation(_layerName, _guiNameList[0], EASING_TYPE_EASEOUTCIRC_ID, USE_PORTRAIT).MoveVec(poAppearAnim, NOTICE_APPER_ANIM_TIME); break; case TOASTNOTICE_ACTION_STATE_ID_DISPLAY: HS2DI laSize = MakeHS2DI(0, 3); _guiAnimator.AddAnimation(_layerName, _guiNameList[5], 0, USE_LANDSCAPE).Scale(laSize, _displayTime); HS2DI poSize = MakeHS2DI(0, 5); _guiAnimator.AddAnimation(_layerName, _guiNameList[5], 0, USE_PORTRAIT).Scale(poSize, _displayTime); break; case TOASTNOTICE_ACTION_STATE_ID_DISAPPEAR: HS2DI laDisAppearAnim = MakeHS2DI(256, 0); _guiAnimator.AddAnimation(_layerName, _guiNameList[0], EASING_TYPE_EASEOUTCIRC_ID, USE_LANDSCAPE).MoveVec(laDisAppearAnim, NOTICE_APPER_ANIM_TIME); HS2DI poDisAppearAnim = MakeHS2DI(512, 0); _guiAnimator.AddAnimation(_layerName, _guiNameList[0], EASING_TYPE_EASEOUTCIRC_ID, USE_PORTRAIT).MoveVec(poDisAppearAnim, NOTICE_APPER_ANIM_TIME); break; case TOASTNOTICE_ACTION_STATE_ID_END: break; default: break; } } private void GUIPosReflesh(){ int toastGUIBaseIndex = 0; HS2DI laBasePos = GetGUIPos(_guiNameList[toastGUIBaseIndex], USE_LANDSCAPE); list laGUIOffsetList = new list(); // アイコン laGUIOffsetList.Add(MakeHS2DI(laBasePos.x() + 15, laBasePos.y() + 10)); // 通知タイプテキスト laGUIOffsetList.Add(MakeHS2DI(laBasePos.x() + 45, laBasePos.y() + 10)); // 通知文 laGUIOffsetList.Add(MakeHS2DI(laBasePos.x() + 15, laBasePos.y() + 40)); // 表示時間シークバー(白) laGUIOffsetList.Add(MakeHS2DI(laBasePos.x() + 15, laBasePos.y() + 85)); // 表示時間シークバー(黒) laGUIOffsetList.Add(MakeHS2DI(laBasePos.x() + 15, laBasePos.y() + 85)); HS2DI poBasePos = GetGUIPos(_guiNameList[toastGUIBaseIndex], USE_PORTRAIT); list poGUIOffsetList = new list(); // アイコン poGUIOffsetList.Add(MakeHS2DI(poBasePos.x() + 30, poBasePos.y() + 20)); // 通知タイプテキスト poGUIOffsetList.Add(MakeHS2DI(poBasePos.x() + 90, poBasePos.y() + 27)); // 通知文 poGUIOffsetList.Add(MakeHS2DI(poBasePos.x() + 30, poBasePos.y() + 80)); // 表示時間シークバー(白) poGUIOffsetList.Add(MakeHS2DI(poBasePos.x() + 30, poBasePos.y() + 186)); // 表示時間シークバー(黒) poGUIOffsetList.Add(MakeHS2DI(poBasePos.x() + 30, poBasePos.y() + 186)); for(int i = 1; i < _guiNameList.Count(); i++){ _guiAnimator.AddAnimation(_layerName, _guiNameList[i], 0, USE_LANDSCAPE).SetPos(laGUIOffsetList[i - 1]); _guiAnimator.AddAnimation(_layerName, _guiNameList[i], 0, USE_PORTRAIT).SetPos(poGUIOffsetList[i - 1]); } } public void ChangeNoticeViewID(int viewID){ ChangeNoticePosHeight(viewID); } private void ChangeNoticePosHeight(int viewID){ int toastGUIBaseIndex = 0; int laViewPosX = GetGUIPos(_guiNameList[toastGUIBaseIndex], USE_LANDSCAPE).x(); int offsetSpace = 5; int laViewPosY = NOTICE_BASE_GUI_DEFAULT_POS_HEIGIHT + ( offsetSpace + NOTICE_BASE_GUI_DEFAULT_SIZE_HEIGHT) * viewID; HS2DI laViewPos = MakeHS2DI(laViewPosX, laViewPosY); int poViewPosX = GetGUIPos(_guiNameList[toastGUIBaseIndex], USE_PORTRAIT).x(); int poViewPosY = laViewPosY * 2; poViewPosY += NOTICE_BASE_GUI_DEFAULT_POS_HEIGIHT_PORTRAIT; HS2DI poViewPos = MakeHS2DI(poViewPosX, poViewPosY); SetGUIPos(_guiNameList[toastGUIBaseIndex], laViewPos, USE_LANDSCAPE); SetGUIPos(_guiNameList[toastGUIBaseIndex], poViewPos, USE_PORTRAIT); } public bool IsEndNoticeAction(){ return _actionStatus.GetCurrentState() == TOASTNOTICE_ACTION_STATE_ID_END; } // 通知が押された時の挙動 public void NoticeForceQuit(){ SendAnctionEvent("OnClick"); if(_noticeTypeID == TOASTNOTICE_TYPE_ERROR_ID){ return; } // エラータイプのトースト通知以外はクリックで閉じる事が出来る _isClicked = true; ChangeActionState(TOASTNOTICE_ACTION_STATE_ID_DISAPPEAR); } public void OnDelete(){ if(_isClicked) { SendAnctionEvent("OnForceQuit"); }else{ SendAnctionEvent("ViewTimeOver"); } for(int i = 0; i < _guiNameList.Count(); i++){ hsReleaseGUI(_layerName, USE_PORTRAIT, _guiNameList[i]); hsReleaseGUI(_layerName, USE_LANDSCAPE, _guiNameList[i]); } } // トースト通知をクリック/通知が消えた時の発火イベント private void SendAnctionEvent(string actionName){ const string LOCALDATAKEY = "toast"; JsVal noticeTypeID = makeJsNumFrom(_noticeTypeID); JsVal identifyKey = makeJsStrFrom(_noticeIdentifyKey); JsVal message = makeJsStrFrom(_noticeText); JsVal sendAction = makeJsStrFrom(actionName); JsVal optionData = makeJsStrFrom(_optionData); JsVal noticeData = makeJsObj(); noticeData.AddPropertyByVal("noticeTypeID", noticeTypeID); noticeData.AddPropertyByVal("identifyKey", identifyKey); noticeData.AddPropertyByVal("message", message); noticeData.AddPropertyByVal("sendAction", sendAction); noticeData.AddPropertyByVal("optionData", optionData); hsSendLocalData(LOCALDATAKEY, noticeData.ToString()); } // GUI座標の変更 private void SetGUIPos(string guiName, HS2DI position, bool userPortraitFlag){ if(userPortraitFlag){ _portraitLayer.SetGUIPos(guiName, position.x(), position.y()); }else{ _landscapeLayer.SetGUIPos(guiName, position.x(), position.y()); } } // GUIの座標取得 private HS2DI GetGUIPos(string guiName, bool userPortraitFlag){ Vector3 guiPos = new Vector3(); if(userPortraitFlag){ _portraitLayer.GetGUIPos(guiName, guiPos.x, guiPos.y); }else{ _landscapeLayer.GetGUIPos(guiName, guiPos.x, guiPos.y); } return MakeHS2DI(guiPos.x, guiPos.y); } private HS2DI MakeHS2DI(int x, int y){ HS2DI hs2di = new HS2DI(); hs2di.SetXY(x, y); return hs2di; } } // --- \Class\TNGUIGenerator.hs --- class TNGUIGenerator{ const string GUI_IMAGE_FILEPATH_BASE = "gui2024/toast_notice/Base.png"; const string GUI_IMAGE_FILEPATH_ICON = "gui2024/toast_notice/IconImages.png"; const string GUI_IMAGE_FILEPATH_TIMEBAR = "gui2024/toast_notice/ViewTimeBar.png"; const bool USE_LANDSCAPE = false; const bool USE_PORTRAIT = true; public TNGUIGenerator(){} // 通知ベース要素生成 public void CreteBase(string layerName, string guiName){ HSButtonModel buttonModel = MakeButtonGUIModel(GUI_IMAGE_FILEPATH_BASE); buttonModel.SetLTRB(MakeRectLTRB(25, 20, 25, 20)); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "button"); laGuiModel.SetButtonModel(buttonModel); laGuiModel.SetSize(MakeHS2DI(256, 100)); laGuiModel.SetPos(MakeHS2DI(0, -18)); laGuiModel.SetRaycastTarget(true); laGuiModel.SetZ(0); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "button"); poGuiModel.SetButtonModel(buttonModel); poGuiModel.SetSize(MakeHS2DI(512, 200)); poGuiModel.SetRaycastTarget(true); poGuiModel.SetZ(0); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); } // 通知アイコン要素生成 public void CreteIcon(string layerName, string guiName, int noticeTypeID){ int imageUVIndex = 0; if(noticeTypeID == TOASTNOTICE_TYPE_WARNING_ID){ imageUVIndex = 1; }else if(noticeTypeID == TOASTNOTICE_TYPE_ERROR_ID){ imageUVIndex = 2; } // アイコン画像の情報生成(UV) int noticeIconSize = 64; int uvPosX = (noticeIconSize + 1) * imageUVIndex; HSRect uv = MakeHSRect(uvPosX, 0, noticeIconSize, noticeIconSize); HSImageModel imageModel = MakeHSImageModel(GUI_IMAGE_FILEPATH_ICON); imageModel.SetUVArea(uv); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "image"); laGuiModel.SetImageModel(imageModel); laGuiModel.SetSize(MakeHS2DI(25, 25)); laGuiModel.SetZ(1); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "image"); poGuiModel.SetImageModel(imageModel); poGuiModel.SetSize(MakeHS2DI(50, 50)); poGuiModel.SetZ(1); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); } // 通知種別テキスト要素生成 public void CreteNoticeTypeText(string layerName, string guiName, int noticeTypeID){ string noticeTypeText = "info"; if(noticeTypeID == TOASTNOTICE_TYPE_WARNING_ID){ noticeTypeText = "Warning"; }else if(noticeTypeID == TOASTNOTICE_TYPE_ERROR_ID){ noticeTypeText = "Error"; } int laFontSize = 18; int poFontSize = 32; HSTextModel laTextModel = MakeHSTextModel(noticeTypeText, laFontSize); laTextModel.SetURLClickable(true); HSTextModel poTextModel = MakeHSTextModel(noticeTypeText, poFontSize); poTextModel.SetURLClickable(true); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "text"); laGuiModel.SetTextModel(laTextModel); laGuiModel.SetSize(MakeHS2DI(128,22)); laGuiModel.SetZ(1); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "text"); poGuiModel.SetTextModel(poTextModel); poGuiModel.SetSize(MakeHS2DI(256, 33)); poGuiModel.SetZ(1); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); } // 通知文要素生成 public void CreteNoticeText(string layerName, string guiName, string noticeText){ int laFontSize = 14; int poFontSize = 28; HSTextModel laTextModel = MakeHSTextModel(noticeText, laFontSize); HSTextModel poTextModel = MakeHSTextModel(noticeText, poFontSize); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "text"); laGuiModel.SetTextModel(laTextModel); laGuiModel.SetSize(MakeHS2DI(235,48)); laGuiModel.SetZ(1); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "text"); poGuiModel.SetTextModel(poTextModel); poGuiModel.SetSize(MakeHS2DI(485, 90)); poGuiModel.SetZ(1); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); } // 表示タイマーのベース要素生成 public void CreteViewTimerBase(string layerName, string guiName){ HSImageModel imageModel = MakeHSImageModel(GUI_IMAGE_FILEPATH_TIMEBAR); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "image"); laGuiModel.SetImageModel(imageModel); laGuiModel.SetSize(MakeHS2DI(220, 3)); laGuiModel.SetZ(1); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "image"); poGuiModel.SetImageModel(imageModel); poGuiModel.SetSize(MakeHS2DI(450, 5)); poGuiModel.SetZ(1); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); HSColor baseColor = MakeHSColor(0.1, 0.1, 0.2 ,1); hsCanvasSetGUIMulColor(layerName, USE_LANDSCAPE, guiName, HSGUIType_Image, baseColor); hsCanvasSetGUIMulColor(layerName, USE_PORTRAIT, guiName, HSGUIType_Image, baseColor); } // 表示タイマーのシークバー要素生成 public void CreteViewTimer(string layerName, string guiName){ HSImageModel imageModel = MakeHSImageModel(GUI_IMAGE_FILEPATH_TIMEBAR); // 横画面 HSGUIModel laGuiModel = MakeCommonHSGUIMoel(guiName, "image"); laGuiModel.SetImageModel(imageModel); laGuiModel.SetSize(MakeHS2DI(220, 3)); laGuiModel.SetZ(2); // 縦画面 HSGUIModel poGuiModel = MakeCommonHSGUIMoel(guiName, "image"); poGuiModel.SetImageModel(imageModel); poGuiModel.SetSize(MakeHS2DI(500, 5)); poGuiModel.SetZ(2); // 登録 hsCanvasAddGUI(layerName, USE_LANDSCAPE, laGuiModel); hsCanvasAddGUI(layerName, USE_PORTRAIT, poGuiModel); HSColor frontColor = MakeHSColor(0.9, 0.9, 0.9 ,0.9); hsCanvasSetGUIMulColor(layerName, USE_LANDSCAPE, guiName, HSGUIType_Image, frontColor); hsCanvasSetGUIMulColor(layerName, USE_PORTRAIT, guiName, HSGUIType_Image, frontColor); } // ImageModelの生成 private HSImageModel MakeHSImageModel(string imageFilePath){ HSImageModel imageModel = new HSImageModel(); imageModel.SetURI(imageFilePath); return imageModel; } // TextModelの生成 private HSTextModel MakeHSTextModel(string text, int fontSize){ HSTextModel textModel = new HSTextModel(); textModel.SetFontSize(fontSize); textModel.SetText(text); textModel.SetFontFamily("BIZUDPGothic"); textModel.SetAlignment("LM"); textModel.SetOverflowWrap(true); HSColor fontColor = MakeHSColor(0.9, 0.9, 0.9 ,1); textModel.SetColor(fontColor); return textModel; } // ButtonModelの生成 public HSButtonModel MakeButtonGUIModel(string imageFilePath){ HSButtonModel buttonModel = new HSButtonModel(); buttonModel.SetFileName(imageFilePath); return buttonModel; } // どのタイプの要素でも共通するセットアップ private HSGUIModel MakeCommonHSGUIMoel(string modelName, string modelType){ HSGUIModel model = new HSGUIModel(); model.SetName(modelName); model.SetShow(true); model.SetType(modelType); model.SetRaycastTarget(false); int defaultZ = 1; model.SetZ(defaultZ); HS2D pivot = new HS2D(); pivot.SetXY(0, 0); model.SetPivot(pivot); model.SetAnchor("RT"); return model; } private HSRectLTRB MakeRectLTRB(int l,int t,int r,int b){ HSRectLTRB ltrb = new HSRectLTRB(); ltrb.SetLTRB(l, t, r, b); return ltrb; } // 座標、サイズ管理用 HS2DI生成関数 private HS2DI MakeHS2DI(int x, int y){ HS2DI hs2di = new HS2DI(); hs2di.SetXY(x, y); return hs2di; } // GUIの色指定用 HSColor生成関数 private HSColor MakeHSColor(float r, float g, float b, float a){ HSColor hsColor = new HSColor(); hsColor.SetRGBA(r, g, b, a); return hsColor; } // UVエリア用 HSRect生成関数 private HSRect MakeHSRect(int x, int y, int w, int h){ HSRect hsrect = new HSRect(); hsrect.SetXYWH(x, y, w, h); return hsrect; } }