private void _CalHorizontal(float x) { int startColumn = (int)(-x / _elementWidth); int startIndex = startColumn * _rowCount; if (startIndex > _elementCount - _showCount) { startIndex = _elementCount - _showCount; } else if (startIndex < 0) { startIndex = 0; } int endIndex = _showCount + startIndex - 1; if (_indexStart != startIndex || _indexEnd != endIndex) { for (int i = 0; i < _showCount; ++i) { if (_elements[i].GetIndex() < startIndex || _elements[i].GetIndex() > endIndex) { _excess.Enqueue(_elements[i]); } } if (startIndex < _indexStart) { for (int i = startIndex; i < _indexStart && i <= endIndex; ++i) { _lack.Enqueue(i); } } if (endIndex > _indexEnd) { for (int i = endIndex; i > _indexEnd && i >= startIndex; --i) { _lack.Enqueue(i); } } int _needIndex = 0; UIGridElement _e = null; while (_lack.Count > 0 & _excess.Count > 0) { _needIndex = _lack.Dequeue(); _e = _excess.Dequeue(); if (_e != null) { int _x = _needIndex / _rowCount; int _y = _needIndex - _x * _rowCount; _e.transform.localPosition = new Vector3(_x * _elementWidth, -_y * _elementHeight, 0); _e.SetIndex(_needIndex); } } _indexStart = startIndex; _indexEnd = endIndex; } }
} // end of HandleMouseInput() /// <summary> /// Helper function to cut down on the cut/paste. /// </summary> /// <param name="e">The element we want info about.</param> /// <param name="invMat">Inverse world matrix of the element.</param> /// <param name="height">Height of the element.</param> /// <param name="width">Width of the element.</param> private void GetElementInfo(UIGridElement e, out Matrix invMat, out float height, out float width) { invMat = e.InvWorldMatrix; UIGrid2DTextureElement te = e as UIGrid2DTextureElement; width = te.Width; height = te.Height; } // end of GetElementInfo()
} // end of HandleTouchInput() private bool TouchHitElement(UIGridElement element, Camera camera, Vector2 screenPos) { float width, height; Matrix invMat; GetElementInfo(element, out invMat, out width, out height); Vector2 hitUV = TouchInput.GetHitUV(screenPos, camera, ref invMat, width, height, useRtCoords: false); return(!((hitUV.X < 0 || hitUV.X > 1) || (hitUV.Y < 0 || hitUV.Y > 1))); }
} // end of UIGrid Refresh() /// <summary> /// Adds a new element to the grid. /// </summary> /// <param name="element">the new element to add</param> /// <param name="i">column for new element</param> /// <param name="j">row for new element</param> public void Add(UIGridElement element, int i, int j) { if (i >= maxDimensions.X || j >= maxDimensions.Y) { throw new Exception(@"Trying to add an element at an index location outside of the grid."); } grid[i, j] = element; actualDimensions.X = Math.Max(actualDimensions.X, i + 1); actualDimensions.Y = Math.Max(actualDimensions.Y, j + 1); dirty = true; } // end of UIGrid Add()
static int RemoveIndexChangeListener(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UIGridElement obj = (UIGridElement)ToLua.CheckObject <UIGridElement>(L, 1); UnityEngine.Events.UnityAction arg0 = (UnityEngine.Events.UnityAction)ToLua.CheckDelegate <UnityEngine.Events.UnityAction>(L, 2); obj.RemoveIndexChangeListener(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int GetIndex(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UIGridElement obj = (UIGridElement)ToLua.CheckObject <UIGridElement>(L, 1); int o = obj.GetIndex(); LuaDLL.lua_pushinteger(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int SetIndex(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UIGridElement obj = (UIGridElement)ToLua.CheckObject <UIGridElement>(L, 1); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); obj.SetIndex(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void HandleGamepadInput() { GamePadInput pad = GamePadInput.GetGamePad0(); UIGridElement e = grid.SelectionElement; UpdateInvertAxis(); string helpID = e.HelpID; string helpText = TweakScreenHelp.GetHelp(helpID); if (helpText != null && Actions.Help.WasPressed) { ShowHelp(helpText); } }
static int set_index(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIGridElement obj = (UIGridElement)o; int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); obj.index = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index index on a nil value")); } }
static int get_index(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIGridElement obj = (UIGridElement)o; int ret = obj.index; LuaDLL.lua_pushinteger(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index index on a nil value")); } }
static int set__element(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIGrid obj = (UIGrid)o; UIGridElement arg0 = (UIGridElement)ToLua.CheckObject <UIGridElement>(L, 2); obj._element = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index _element on a nil value")); } }
static int get__element(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIGrid obj = (UIGrid)o; UIGridElement ret = obj._element; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index _element on a nil value")); } }
} // end of BrushPicker UpdateIndex() public bool TouchIsOverBrushSelection(TouchContact touch, Camera camera) { float width; float height; Matrix invMat; // Test in-focus element for hit. UIGridElement e = grid.SelectionElement; if (e != null) { GetElementInfo(e, out invMat, out width, out height); Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref invMat, width, height, useRtCoords: false); if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1) { return(true); } } return(false); }
public override void Update() { if (UpdateMessages()) { return; } // If we signed out of LIVE, back out to the main menu. if (!GamerServices.SignedInToLive) { parent.ActivateMainMenu(); return; } // If we are joining a share session by accepting an invite from the Dashboard, bail now; we're just waiting for this // operation to complete then we'll open the sharing screen. if (LiveManager.JoiningShareInvitation) { return; } // If we are accepting an invite via the Guide interface, start joining the session. if (LiveManager.AcceptedShareInvitation) { parent.openingSharingRoomMessage.Activate(); // Change state from "accepting" to "joining" the invited session. LiveManager.AcceptedShareInvitation = false; LiveManager.JoiningShareInvitation = true; // Disable the share hub UI. shared.grid.Active = false; // Cancel pending LIVE queries. LiveManager.ClearQueuedOperations(null); // Start joining the invited session. InvitedSessionJoiner joinerOp = new InvitedSessionJoiner(parent.JoinSessionComplete_ActivateSharingScreen, null, parent); joinerOp.Queue(); return; } // Don't do any input processing if the guide is up. if (GamerServices.IsGuideVisible) { return; } // Check for mouse press on bottom tile. // hit is in pixels in screen coords (before overscan adjustment) Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(shared.camera, true); bool openPressed = false; if (shared.openBox.LeftPressed(hit)) { openPressed = true; } GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.StartSharing.WasPressed || openPressed || shared.forceSessionRestart) { Actions.StartSharing.ClearAllWasPressedState(); shared.forceSessionRestart = false; // User selected "Enter Sharing Room" if (!LiveManager.IsConnected) { LiveManager.FriendUpdatesEnabled = false; LiveManager.JoinableUpdatesEnabled = false; parent.openingSharingRoomMessage.Activate(); LiveManager.ClearQueuedOperations(null); SessionCreator createOp = new SessionCreator(parent.SessionCreatorComplete_ActivateSharingScreen, null, this); createOp.Queue(); } else { parent.ActivateSharingScreen(); } } // If we're still active, ensure that the friends list is up to date. // We don't want to do this if not active since we'll just end up // adding all our friends to the grid which we just cleared... if (shared.grid.Active) { // We're not accepting or joining an invited session, and we're still logged in to LIVE, so update the friend menu to reflect their current status bits. List <LiveFriend> friends = LiveManager.Friends; bool refreshGrid = false; foreach (LiveFriend friend in friends) { UIGridShareFriendElement elem = shared.FindFriendElement(friend.GamerTag); // Build the menu on the fly. if (elem == null && friend.IsFriend) { elem = new UIGridShareFriendElement(friend); shared.elements.Add(elem); refreshGrid = true; } else if (elem != null && !friend.IsFriend) { shared.elements.Remove(elem); refreshGrid = true; } } // If we've changed the list, call update on the grid again so // that it's in a good state for rendering. if (refreshGrid) { shared.RefreshGrid(); } } Matrix parentMatrix = Matrix.Identity; shared.grid.Update(ref parentMatrix); // Only care about mouse input on the grid if the grid is not empty. if (shared.grid.ActualDimensions != Point.Zero) { // Mouse Input. // Scroll wheel is handled by the grid. // Clicking on Invite square should send invite. // Clicking on user tile should bring that user into focus. // Check if mouse hitting current selection object. UIGridElement e = shared.grid.SelectionElement; Matrix mat = Matrix.Invert(e.WorldMatrix); Vector2 hitUV = MouseInput.GetHitUV(shared.camera, ref mat, e.Size.X, e.Size.Y, true); bool focusElementHit = false; if (hitUV.X >= 0 && hitUV.X < 1.25 && hitUV.Y >= 0 && hitUV.Y < 1) { focusElementHit = true; // See if we hit the "invite/join" tile which is // to the right of the main part of the tile. if (hitUV.X > 1) { if (MouseInput.Left.WasPressed) { MouseInput.ClickedOnObject = this; } if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this) { parent.OnSelect(shared.grid); } } } // If we didn't hit the focus object, see if we hit any of the others. // If so, bring them into focus. if (!focusElementHit && MouseInput.Left.WasPressed) { for (int i = 0; i < shared.grid.ActualDimensions.Y; i++) { if (i == shared.grid.SelectionIndex.Y) { continue; } e = shared.grid.Get(0, i); mat = Matrix.Invert(e.WorldMatrix); hitUV = MouseInput.GetHitUV(shared.camera, ref mat, e.Size.X, e.Size.Y, true); if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1) { // We hit an element, so bring it into focus. shared.grid.SelectionIndex = new Point(0, i); break; } } } } } // end of Update()
public void ApplySetting() { if (null == _scrollRect) { if (null == GetScrollRect()) { Debug.LogError("UIGrid ApplySetting ScrollRect is null"); return; } } //_scrollRect.content.anchoredPosition = Vector2.zero; if (_isVertical) { _columnCount = _constraintCount; _rowCount = Mathf.CeilToInt((float)_elementCount / _constraintCount); _showCount = (int)((_scrollRect.viewport.rect.height / _elementHeight) + 2) * _columnCount; } else { _rowCount = _constraintCount; _columnCount = Mathf.CeilToInt((float)_elementCount / _constraintCount); _showCount = (int)((_scrollRect.viewport.rect.width / _elementWidth) + 2) * _rowCount; } _scrollRect.content.sizeDelta = new Vector2(_columnCount * _elementWidth, _rowCount * _elementHeight); _scrollRect.normalizedPosition = new Vector2(0, 1); _showCount = Mathf.Min(_showCount, _elementCount); for (int i = 0; i < _elements.Count; ++i) { _elements[i].gameObject.SetActive(true); _elements[i].index = -1; } if (_elements.Count < _showCount) { for (int i = _elements.Count; i < _showCount; ++i) { if (_element != null) { UIGridElement _ge = Object.Instantiate(_element); if (_ge != null) { _elements.Add(_ge); _ge.transform.SetParent(_scrollRect.content); _ge.transform.localScale = Vector3.one; _ge.gameObject.SetActive(true); _ge.index = -1; if (null != onAddElement) { onAddElement(_ge.gameObject); } } } } } else if (_elements.Count > _showCount) { for (int i = _showCount; i < _elements.Count; ++i) { _elements[i].gameObject.SetActive(false); } } _indexStart = -1; _indexEnd = -1; OnValueChanged(new Vector2(0, 1)); }
private void InitGrid() { grid = new UIGrid(OnSelect, OnCancel, new Point(1, 10), "OptionsMenuGrid"); grid.LocalMatrix = Matrix.CreateTranslation(0.25f / 96.0f, 0.25f / 96.0f, 0.0f); grid.RenderEndsIn = true; grid.UseMouseScrollWheel = true; // Create a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); //blob.width = 5.0f; //blob.height = 1.0f; blob.width = 512.0f / 96.0f; blob.height = blob.width / 5.0f; blob.edgeSize = 0.06f; blob.Font = UI2D.Shared.GetGameFont24Bold; blob.textColor = Color.White; blob.dropShadowColor = Color.Black; blob.useDropShadow = true; blob.invertDropShadow = false; blob.unselectedColor = new Color(new Vector3(4, 100, 90) / 255.0f); blob.selectedColor = new Color(new Vector3(5, 180, 160) / 255.0f); blob.normalMapName = @"Slant0Smoothed5NormalMap"; blob.justify = UIGridModularCheckboxElement.Justification.Left; // // Create elements here. // int index = 0; { showToolTips = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showToolTips")); showToolTips.OnCheck = delegate() { XmlOptionsData.ShowToolTips = true; }; showToolTips.OnClear = delegate() { XmlOptionsData.ShowToolTips = false; }; showToolTips.HelpID = "ShowToolTips"; // Add to grid. grid.Add(showToolTips, 0, index++); } { showHints = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showHints")); showHints.OnCheck = delegate() { XmlOptionsData.ShowHints = true; }; showHints.OnClear = delegate() { XmlOptionsData.ShowHints = false; }; showHints.HelpID = "ShowHints"; // Add to grid. grid.Add(showHints, 0, index++); } { restoreDisabledHints = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.restoreDisabledHints")); restoreDisabledHints.OnCheck = delegate() { XmlOptionsData.RestoreDisabledHints(); }; restoreDisabledHints.OnClear = delegate() { restoreDisabledHints.Check = true; }; restoreDisabledHints.HelpID = "RestoreDisabledHints"; // Add to grid. grid.Add(restoreDisabledHints, 0, index++); } { showFramerate = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showFramerate")); showFramerate.OnCheck = delegate() { XmlOptionsData.ShowFramerate = true; }; showFramerate.OnClear = delegate() { XmlOptionsData.ShowFramerate = false; }; showFramerate.HelpID = "ShowFramerate"; // Add to grid. grid.Add(showFramerate, 0, index++); } /* * { * helpLevel = new UIGridModularRadioBoxElement(blob, Strings.Localize("optionsParams.helpLevel")); * helpLevel.AddText(Strings.Localize("optionsParams.lowHelp")); * helpLevel.AddText(Strings.Localize("optionsParams.midHelp")); * helpLevel.AddText(Strings.Localize("optionsParams.highHelp")); * helpLevel.CurIndex = XmlOptionsData.HelpLevel; * helpLevel.OnChange = delegate(UIGridModularRadioBoxElement.ListEntry entry) * { * XmlOptionsData.HelpLevel = helpLevel.CurIndex; * }; * helpLevel.HelpID = "HelpOverlayAmount"; * // Add to grid. * grid.Add(helpLevel, 0, index++); * } */ { float oldWidth = blob.width; blob.width += 0.5f; language = new UIGridModularRadioBoxElement(blob, Strings.Localize("optionsParams.language")); blob.width = oldWidth; IEnumerable <LocalizationResourceManager.SupportedLanguage> langs = LocalizationResourceManager.SupportedLanguages; // Copy to a List so we can sort. List <LocalizationResourceManager.SupportedLanguage> languageList = new List <LocalizationResourceManager.SupportedLanguage>(); foreach (LocalizationResourceManager.SupportedLanguage lang in langs) { languageList.Add(lang); } languageList.Sort(LanguageSortComp); // Add the sorted languages to the UI element. foreach (LocalizationResourceManager.SupportedLanguage lang in languageList) { #if NETFX_CORE if (lang.NameInEnglish.Equals("hebrew", StringComparison.OrdinalIgnoreCase)) #else if (lang.NameInEnglish.Equals("hebrew", StringComparison.InvariantCultureIgnoreCase)) #endif { // RtoL code seems to have trouble with NSM characters 0x05b0 and 0x05b4. // Strip them out. string native = ""; char[] a = lang.NameInNative.ToCharArray(); foreach (char c in a) { if (c != 0x05b0 && c != 0x05b4) { native += c; } } language.AddText(lang.NameInEnglish + " : " + native, lang.Language); } else { language.AddText(lang.NameInEnglish + " : " + lang.NameInNative, lang.Language); } } language.NumColumns = 2; language.SetValueByKey(XmlOptionsData.Language); language.OnChange = delegate(UIGridModularRadioBoxElement.ListEntry entry) { // Note we can only get away with this since the language won't change for real until restart. XmlOptionsData.Language = language.CurKey; }; language.HelpID = "Language"; // Add to grid. grid.Add(language, 0, index++); } { modalToolMenu = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.ModalToolMenu")); modalToolMenu.OnCheck = delegate() { XmlOptionsData.ModalToolMenu = true; }; modalToolMenu.OnClear = delegate() { XmlOptionsData.ModalToolMenu = false; }; modalToolMenu.HelpID = "ModalToolMenu"; // Add to grid. grid.Add(modalToolMenu, 0, index++); } #region Stick Inverting { invertYAxis = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertYAxis")); invertYAxis.OnCheck = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertYAxis(lastTouched, true); }; invertYAxis.OnClear = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertYAxis(lastTouched, false); }; invertYAxis.HelpID = "InvertYAxis"; grid.Add(invertYAxis, 0, index++); } { invertXAxis = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertXAxis")); invertXAxis.OnCheck = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertXAxis(lastTouched, true); }; invertXAxis.OnClear = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertXAxis(lastTouched, false); }; invertXAxis.HelpID = "InvertXAxis"; grid.Add(invertXAxis, 0, index++); } { invertCamY = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertCamY")); invertCamY.OnCheck = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertCamY(lastTouched, true); }; invertCamY.OnClear = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertCamY(lastTouched, false); }; invertCamY.HelpID = "InvertCamY"; grid.Add(invertCamY, 0, index++); } { invertCamX = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertCamX")); invertCamX.OnCheck = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertCamX(lastTouched, true); }; invertCamX.OnClear = delegate() { PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched); GamePadInput.SetInvertCamX(lastTouched, false); }; invertCamX.HelpID = "InvertCamX"; grid.Add(invertCamX, 0, index++); } #endregion Stick Inverting #region Terrain Edit Speed { // Restore default. blob.height = blob.width / 5.0f; terrainSpeed = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.terrainSpeed")); terrainSpeed.MinValue = 0.25f; terrainSpeed.MaxValue = 4.0f; terrainSpeed.IncrementByAmount = 0.25f; terrainSpeed.NumberOfDecimalPlaces = 2; terrainSpeed.OnChange = delegate(float speed) { XmlOptionsData.TerrainSpeed = speed; }; terrainSpeed.HelpID = "TerrainSpeed"; grid.Add(terrainSpeed, 0, index++); } #endregion Terrain Edit Speed #region Audio Volumes { // Restore default. blob.height = blob.width / 5.0f; uiVolume = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.uiVolume")); uiVolume.MinValue = 0.0f; uiVolume.MaxValue = 100.0f; uiVolume.IncrementByAmount = 5.0f; uiVolume.NumberOfDecimalPlaces = 0; uiVolume.OnChange = delegate(float volume) { XmlOptionsData.UIVolume = volume * 0.01f; }; uiVolume.HelpID = "UIVolume"; grid.Add(uiVolume, 0, index++); } { foleyVolume = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.foleyVolume")); foleyVolume.MinValue = 0.0f; foleyVolume.MaxValue = 100.0f; foleyVolume.IncrementByAmount = 5.0f; foleyVolume.NumberOfDecimalPlaces = 0; foleyVolume.OnChange = delegate(float volume) { XmlOptionsData.FoleyVolume = volume * 0.01f; }; foleyVolume.HelpID = "EffectsVolume"; grid.Add(foleyVolume, 0, index++); } { musicVolume = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.musicVolume")); musicVolume.MinValue = 0.0f; musicVolume.MaxValue = 100.0f; musicVolume.IncrementByAmount = 5.0f; musicVolume.NumberOfDecimalPlaces = 0; musicVolume.OnChange = delegate(float volume) { XmlOptionsData.MusicVolume = volume * 0.01f; }; musicVolume.HelpID = "MusicVolume"; grid.Add(musicVolume, 0, index++); } #endregion Audio Volumes #region Privacy Settings { checkForUpdates = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.checkForUpdates")); checkForUpdates.OnCheck = delegate() { XmlOptionsData.CheckForUpdates = true; }; checkForUpdates.OnClear = delegate() { XmlOptionsData.CheckForUpdates = false; }; checkForUpdates.HelpID = "CheckForUpdates"; // Add to grid. grid.Add(checkForUpdates, 0, index++); } { sendInstrumentation = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.sendInstrumentation")); sendInstrumentation.OnCheck = delegate() { XmlOptionsData.SendInstrumentation = true; }; sendInstrumentation.OnClear = delegate() { XmlOptionsData.SendInstrumentation = false; }; sendInstrumentation.HelpID = "SendInstrumentation"; // Add to grid. grid.Add(sendInstrumentation, 0, index++); } { UIGridModularButtonElement.UIButtonElementEvent onA = delegate() { Process.Start(Program2.SiteOptions.KGLUrl + @"/EULA#code_of_conduct"); }; showCodeOfConduct = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewCodeOfConduct"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null); showCodeOfConduct.HelpID = "ShowCodeOfConduct"; grid.Add(showCodeOfConduct, 0, index++); } { UIGridModularButtonElement.UIButtonElementEvent onA = delegate() { Process.Start(Program2.SiteOptions.KGLUrl + @"/privacy"); }; showPrivacyStatement = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewPrivacyStatement"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null); showPrivacyStatement.HelpID = "ShowPrivacyStatement"; grid.Add(showPrivacyStatement, 0, index++); } { UIGridModularButtonElement.UIButtonElementEvent onA = delegate() { Process.Start(Program2.SiteOptions.KGLUrl + @"/EULA#eula"); }; showEULA = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewEULA"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null); showEULA.HelpID = "ShowEULA"; grid.Add(showEULA, 0, index++); } #endregion #region ShowIntroVideo { showIntroVideo = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showIntroVideo")); showIntroVideo.OnCheck = delegate() { XmlOptionsData.ShowIntroVideo = true; }; showIntroVideo.OnClear = delegate() { XmlOptionsData.ShowIntroVideo = false; }; showIntroVideo.HelpID = "ShowIntroVideo"; // Add to grid. grid.Add(showIntroVideo, 0, index++); } #endregion #region ShowTutorialDebug { showTutorialDebug = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showTutorialDebug")); showTutorialDebug.OnCheck = delegate() { XmlOptionsData.ShowTutorialDebug = true; }; showTutorialDebug.OnClear = delegate() { XmlOptionsData.ShowTutorialDebug = false; }; showTutorialDebug.HelpID = "ShowTutorialDebug"; // Add to grid. grid.Add(showTutorialDebug, 0, index++); } #endregion showVersion = new UIGridModularButtonElement(blob, Strings.Localize("shareHub.appName") + " (" + Program2.ThisVersion.ToString() + ", " + Program2.SiteOptions.Product + ")", null, null, null, null); showVersion.HelpID = "Version"; grid.Add(showVersion, 0, index++); // // Set grid properties. // grid.Spacing = new Vector2(0.0f, 0.1f); // The first number doesn't really matter since we're doing a 1d column. grid.Scrolling = true; grid.Wrap = false; grid.LocalMatrix = Matrix.Identity; // Loop over al the elements in the grid. For any that have // help, set the flag so they display Y button for help. for (int i = 0; i < grid.ActualDimensions.Y; i++) { UIGridElement e = grid.Get(0, i); string helpID = e.HelpID; string helpText = TweakScreenHelp.GetHelp(helpID); if (helpText != null) { e.ShowHelpButton = true; } } } // end of InitGrid
public override bool HandleMouseInput(Camera camera) { float width; float height; Matrix invMat; bool handled = false; // Test in-focus element for hit. UIGridElement e = grid.SelectionElement; if (e != null) { GetElementInfo(e, out invMat, out width, out height); Vector2 hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false); if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1) { if (MouseInput.Left.WasPressed) { MouseInput.ClickedOnObject = e; handled = true; } if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e) { SelectCurrentChoice(); Foley.PlayPressA(); return(true); } } // Test elements not in focus. If one is hit, bring it to the fore. // Need to test inside out so that if any overlap we test the front // ones first and react to them. If we find a UV hit with a tile // we break to skip testing the rest. // Left side first. for (int i = grid.SelectionIndex.X - 1; i >= 0; i--) { e = grid.Get(i, 0); GetElementInfo(e, out invMat, out width, out height); hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false); if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1) { if (MouseInput.Left.WasPressed) { MouseInput.ClickedOnObject = e; handled = true; } if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e) { int steps = grid.SelectionIndex.X - i; while (steps > 0) { DecrementFocus(); --steps; } handled = true; } break; } } // Now the right side. for (int i = grid.SelectionIndex.X + 1; i < grid.ActualDimensions.X; i++) { e = grid.Get(i, 0); GetElementInfo(e, out invMat, out width, out height); hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false); if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1) { if (MouseInput.Left.WasPressed) { MouseInput.ClickedOnObject = e; handled = true; } if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e) { int steps = i - grid.SelectionIndex.X; while (steps > 0) { IncrementFocus(); --steps; } handled = true; } break; } } } return(handled); } // end of HandleMouseInput()
private void HandleMouseInput() { if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse) { return; } // If in focus element has help available, get it. UIGridElement e = grid.SelectionElement; string helpID = e.HelpID; string helpText = TweakScreenHelp.GetHelp(helpID); bool hitAnything = false; // Check for help tile. Matrix mat = Matrix.CreateTranslation(-helpSquare.Position.X, -helpSquare.Position.Y, 0); Vector2 hitUV = MouseInput.GetHitUV(camera, ref mat, helpSquare.Size, helpSquare.Size, true); if (grid.SelectionElement.ShowHelpButton) { if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1) { if (MouseInput.Left.WasPressed) { MouseInput.ClickedOnObject = helpSquare; } if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == helpSquare) { if (helpText != null) { ShowHelp(helpText); } } hitAnything = true; } } // Check if mouse hitting current selection object. Or should this be done in the object? mat = Matrix.Invert(e.WorldMatrix); hitUV = MouseInput.GetHitUV(camera, ref mat, e.Size.X, e.Size.Y, true); bool focusElementHit = false; if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1) { e.HandleMouseInput(hitUV); focusElementHit = true; hitAnything = true; } // If we didn't hit the focus object, see if we hit any of the others. // If so, bring them into focus. if (!focusElementHit && MouseInput.Left.WasPressed) { for (int i = 0; i < grid.ActualDimensions.Y; i++) { if (i == grid.SelectionIndex.Y) { continue; } e = grid.Get(0, i); mat = Matrix.Invert(e.WorldMatrix); hitUV = MouseInput.GetHitUV(camera, ref mat, e.Size.X, e.Size.Y, true); if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1) { // We hit an element, so bring it into focus. grid.SelectionIndex = new Point(0, i); hitAnything = true; break; } } } // Check for edges of screen. if (MouseInput.AtWindowTop()) { grid.MoveUp(); } if (MouseInput.AtWindowBottom()) { grid.MoveDown(); } // Allow right click or left click on nothing to exit. if (MouseInput.Right.WasPressed || (!hitAnything && MouseInput.Left.WasPressed)) { Deactivate(); } }
} // end of Update() private void HandleTouchInput() { if (GamePadInput.ActiveMode != GamePadInput.InputMode.Touch) { return; } if (TouchInput.TouchCount == 0) { return; } bool hitMenu = false; TouchContact touch = TouchInput.GetOldestTouch(); // If in focus element has help available, get it. UIGridElement focusElement = grid.SelectionElement; string helpID = focusElement.HelpID; string helpText = TweakScreenHelp.GetHelp(helpID); // Check for help tile. Matrix mat = Matrix.CreateTranslation(-helpSquare.Position.X, -helpSquare.Position.Y, 0); if (touch != null) { Vector2 hitHelpUV = Vector2.Zero; hitHelpUV = TouchInput.GetHitUV(touch.position, camera, ref mat, helpSquare.Size, helpSquare.Size, true); if (grid.SelectionElement.ShowHelpButton) { if (hitHelpUV.X >= 0 && hitHelpUV.X < 1 && hitHelpUV.Y >= 0 && hitHelpUV.Y < 1) { if (TouchInput.WasTouched) { touch.TouchedObject = helpSquare; } if (TouchInput.WasReleased && touch.TouchedObject == helpSquare) { if (helpText != null) { ShowHelp(helpText); } } hitMenu = true; } } // Check if mouse hitting current selection object. Or should this be done in the object? mat = Matrix.Invert(focusElement.WorldMatrix); Vector2 hitFocusUV = TouchInput.GetHitUV(touch.position, camera, ref mat, focusElement.Size.X, focusElement.Size.Y, true); bool focusElementHit = false; if (hitFocusUV.X >= 0 && hitFocusUV.X < 1 && hitFocusUV.Y >= 0 && hitFocusUV.Y < 1) { if (touch.phase == TouchPhase.Began) { touch.TouchedObject = focusElement; } focusElement.HandleTouchInput(touch, hitFocusUV); focusElementHit = true; hitMenu = true; } // If we didn't hit the focus object, see if we hit any of the others. // If so, bring them into focus. if (!focusElementHit && TouchGestureManager.Get().TapGesture.WasTapped()) { for (int i = 0; i < grid.ActualDimensions.Y; i++) { if (i == grid.SelectionIndex.Y) { continue; } UIGridElement e = grid.Get(0, i); mat = Matrix.Invert(e.WorldMatrix); Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref mat, e.Size.X, e.Size.Y, true); if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1) { // We hit an element, so bring it into focus. grid.SelectionIndex = new Point(0, i); hitMenu = true; break; } } } if ((hitFocusUV.X >= 0) && (hitFocusUV.X < 1)) { hitMenu = true; } if (!hitMenu && TouchGestureManager.Get().TapGesture.WasTapped()) { Deactivate(); } // Handle free-form scrolling if (touch.TouchedObject != focusElement) { grid.HandleTouchInput(camera); } } // end of touch input }
} // end of c'tor public void Update() { changeLanguageMessage.Update(camera); if (active && CommandStack.Peek() == grid.CommandMap) { UIGridElement prevE = grid.SelectionElement; HandleTouchInput(); HandleMouseInput(); HandleGamepadInput(); // Update the grid. grid.Update(ref worldGrid); // If the Update deactived us, bail. if (!active) { return; } // Update help square's positioning to line up with current selection. Vector3 selectionElementOffset = grid.SelectionElement.Position - grid.ScrollOffset; helpSquare.Position = new Vector2(helpSquare.Position.X, selectionElementOffset.Y); // For each element in the grid, calc it's screen space Y position // and give it a slight twist around the Y axis based on this. // Note this assumes that this grid is 1d vertical. for (int j = 0; j < grid.ActualDimensions.Y; j++) { UIGridElement e = grid.Get(0, j); Vector3 pos = Vector3.Transform(e.Position, grid.WorldMatrix); Vector3 rot = Vector3.Zero; float rotationScaling = 0.2f; rot.Y = -rotationScaling * pos.Y; e.Rotation = rot; } if (prevE != grid.SelectionElement) { if (grid.SelectionElement.ShowHelpButton) { helpSquare.Show(); } else { helpSquare.Hide(); } } helpSquare.Update(); GamePadInput.ClearAllWasPressedState(); } // end of if active and have input focus. // Update the text displays. Internally they check if they're active before doing anything. if (active) { InGame.inGame.shared.smallTextDisplay.Update(camera); InGame.inGame.shared.scrollableTextDisplay.Update(camera); } } // end of Update()