public DoodadUI(HullDataManager hullData) { _hullData = hullData; var buttonGen = new ButtonGenerator("ToolbarButton64.json"); buttonGen.X = 50; buttonGen.Y = 50; buttonGen.TextureName = "DeckNavArrowUp"; _deckUpButton = buttonGen.GenerateButton(); buttonGen.Y = 50 + 64; buttonGen.TextureName = "DeckNavArrowDown"; _deckDownButton = buttonGen.GenerateButton(); _deckUpButton.OnLeftClickDispatcher += AddVisibleLevel; _deckDownButton.OnLeftClickDispatcher += RemoveVisibleLevel; _toolBar = new Toolbar("Templates/DoodadToolbar.json"); _toolBar.BindButtonToTool(0, new WallMenuTool( hullData) ); /*_toolBar.BindButtonToTool(1, new LadderBuildTool( geometryInfo, VisibleDecks ));*/ }
public BezierCurve(float offsetX, float offsetY, CurveInitalizeData initData) { float initX = initData.HandlePosX + offsetX; float initY = initData.HandlePosY + offsetY; _nextLines = null; _nextCurve = null; _prevCurve = null; _prevLines = null; _lineTemplate = new LineGenerator(); _lineTemplate.V1 = Vector2.Zero; _lineTemplate.V2 = Vector2.Zero; _lineTemplate.Color = Color.White; _lineTemplate.Depth = DepthLevel.Low; Vector2 component1 = Common.GetComponentFromAngle(initData.Angle, initData.Length1); Vector2 component2 = Common.GetComponentFromAngle((float) (initData.Angle - Math.PI), initData.Length2); // minus math.pi to reverse direction #region stuff for generating ui elements var buttonTemplate = new ButtonGenerator("HullEditorHandle.json"); var lineTemplate = new LineGenerator("HullEditorLine.json"); Handle = new CurveHandle(buttonTemplate, lineTemplate, new Vector2(initX, initY), component1, component2); #endregion }
public TestState() { var t = new TerrainGen(); var sw = new Stopwatch(); sw.Start(); //t.GenerateChunk(i, 0); sw.Stop(); double d = sw.ElapsedMilliseconds / 500d; int g = 5; target = new RenderTarget(); //sprite = new Sprite2D(target, "TestTexture", 0, 0, 50, 50); var buttongen = new ButtonGenerator("ToolbarButton64.json"); buttongen.RenderTarget = target; buttongen.TextureName = "UI_TestTexture"; buttongen.X = 0; buttongen.Y = 0; button = buttongen.GenerateButton(); buttongen.X = 64; buttongen.Y = 0; button1 = buttongen.GenerateButton(); }
void Start() { buttonGenerator = FindObjectOfType <ButtonGenerator>(); // Set up action buttonGenerator.ViewPart += ButtonGenerator_ViewPart; labelPrefab.SetActive(false); }
// Start is called before the first frame update void Start() { sentences = new Queue <string>(); speakers = new Queue <Speaker>(); buttonGenerator = DecisionPanel.Value.GetComponent <ButtonGenerator>(); characterPotrait = CharacterPotrait.Value.GetComponent <Image>(); DialogPanel.Value = false; }
public CustomMessageBoxWithContent(FrameworkElement content, string title, params string[] buttons) { if (content != null) { Content = content; } if (title != null) { Title = new TextBlock() { Text = title, FontSize = 30, Foreground = new SolidColorBrush(Colors.Black), TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap } } ; if (buttons != null && buttons.Length > 0) { SpButtons = new StackPanel() { Orientation = Orientation.Horizontal }; ButtonAdvanced[] array = ButtonGenerator.Generate(90, 12, buttons); for (int i = 0; i < array.Length; i++) { array[i].Click += button_Click; SpButtons.Children.Add(array[i]); } //auto focus first (default) button if (AutoFocusDefaultButton && array.Length > 0) { array[0].Loaded += (s, e) => { (s as ButtonAdvanced).Focus(FocusState.Keyboard); } } ; base.Buttons = SpButtons; } } void button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { SendResponse(SpButtons.Children.IndexOf(sender as Button)); } } }
/// <summary> /// </summary> /// <param name="buttonTemplate"> </param> /// <param name="lineTemplate"> </param> /// <param name="pos"> </param> /// <param name="prevComponent"> </param> /// <param name="nextComponent"> </param> public CurveHandle(ButtonGenerator buttonTemplate, LineGenerator lineTemplate, Vector2 pos, Vector2 prevComponent, Vector2 nextComponent) { buttonTemplate = new ButtonGenerator("HullEditorHandle.json"); buttonTemplate.Identifier = (int) HandleType.Center; buttonTemplate.X = pos.X; buttonTemplate.Y = pos.Y; _centerButton = buttonTemplate.GenerateButton(); _centerButton.GetComponent<DraggableComponent>().DragMovementDispatcher += TranslateToLinks; _centerButton.GetComponent<DraggableComponent>().DragMovementClamp += ClampHandleMovement; buttonTemplate.Identifier = (int) HandleType.Prev; buttonTemplate.X = prevComponent.X + pos.X; buttonTemplate.Y = prevComponent.Y + pos.Y; _prevButton = buttonTemplate.GenerateButton(); _prevButton.GetComponent<DraggableComponent>().DragMovementDispatcher += TranslateToLinks; _prevButton.GetComponent<DraggableComponent>().DragMovementClamp += ClampHandleMovement; buttonTemplate.Identifier = (int) HandleType.Next; buttonTemplate.X = nextComponent.X + pos.X; buttonTemplate.Y = nextComponent.Y + pos.Y; _nextButton = buttonTemplate.GenerateButton(); _nextButton.GetComponent<DraggableComponent>().DragMovementDispatcher += TranslateToLinks; _nextButton.GetComponent<DraggableComponent>().DragMovementClamp += ClampHandleMovement; _prevLine = lineTemplate.GenerateLine(); _nextLine = lineTemplate.GenerateLine(); _prevLine.OriginPoint = _centerButton.CentPosition; _prevLine.DestPoint = _prevButton.CentPosition; _nextLine.OriginPoint = _centerButton.CentPosition; _nextLine.DestPoint = _nextButton.CentPosition; _nextButton.GetComponent<FadeComponent>().ForceFadeout(); _prevButton.GetComponent<FadeComponent>().ForceFadeout(); _centerButton.GetComponent<FadeComponent>().ForceFadeout(); _prevLine.GetComponent<FadeComponent>().ForceFadeout(); _nextLine.GetComponent<FadeComponent>().ForceFadeout(); _nextButton.GetComponent<FadeComponent>().ForceFadeout(); _prevButton.GetComponent<FadeComponent>().ForceFadeout(); _centerButton.GetComponent<FadeComponent>().ForceFadeout(); _prevLine.GetComponent<FadeComponent>().ForceFadeout(); _nextLine.GetComponent<FadeComponent>().ForceFadeout(); InterlinkButtonEvents(); }
public Toolbar(string path){ var sr = new StreamReader(path); var str = sr.ReadToEnd(); var ctorData = JsonConvert.DeserializeObject<ToolbarCtorData>(str); _Enabled = true; #region some validity checks if (ctorData.ButtonIcons == null) throw new InvalidDataException("ButtonIcons invalid"); if (ctorData.NumButtons == 0) throw new InvalidDataException("NumButtons invalid"); if (ctorData.ButtonIcons.Length != ctorData.NumButtons) throw new InvalidDataException("NumButtons is not equal to the number of ButtonIcons"); #endregion #region set ctor data _position = ctorData.Position; _buttonSize = ctorData.ButtonSize; _orientation = ctorData.Orientation; _numButtons = ctorData.NumButtons; #endregion #region create the buttons var buttonGen = new ButtonGenerator(ctorData.ButtonTemplate); ToolbarButtons = new Button[ctorData.NumButtons]; int xPos = _position.X; int yPos = _position.Y; int xIncrement = 0, yIncrement = 0; if (_orientation == ToolbarOrientation.Horizontal) xIncrement = _buttonSize.X; else yIncrement = _buttonSize.Y; for (int i = 0; i < ctorData.NumButtons; i++){ buttonGen.Identifier = i; buttonGen.X = xPos; buttonGen.Y = yPos; buttonGen.TextureName = ctorData.ButtonIcons[i]; ToolbarButtons[i] = buttonGen.GenerateButton(); xPos += xIncrement; yPos += yIncrement; } foreach (var button in ToolbarButtons){ button.OnLeftClickDispatcher += HandleButtonClick; } #endregion #region finalize construction _nullTool = new NullTool(); _activeTool = _nullTool; _buttonTools = new IToolbarTool[_numButtons]; for (int i = 0; i < _numButtons; i++) _buttonTools[i] = _nullTool; #endregion }
//Generates Menu for scene from DB static public void GenerateMenu() { Scene scene = SceneManager.GetActiveScene();//get current scene //Menu menu = DatabaseGetMenu(sceneName) or whatever this function will eventually be //create some test Options/Menu /* * Option[] options = new Option[4]; * options[0] = new Option("Train", "train", 0); * options[1] = new Option("Fight", "fight", 2); * options[2] = new Option("Stunt", "stunt"); * options[3] = new Option("Remember Dre.", "rememberDre"); * Menu menu = new Menu("Test Menu", options); */ //create canvas for menu GameObject newCanvas = new GameObject("Canvas", typeof(Canvas)); newCanvas.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; //set rendermode to Screen Space Overlay for reasons newCanvas.transform.position = Vector3.zero; //center canvas newCanvas.AddComponent <GraphicRaycaster>(); //add Raycaster so buttons work Debug.Log(scene.name); Type sceneScript = Type.GetType(scene.name);//get name of script file with option functions Debug.Log(sceneScript); //get Menu object of menu Menu menu = (Menu)sceneScript.GetMethod("getMenu").Invoke(null, null); //MethodInfo method = sceneScript.GetMethod(options[0].func); //Debug.Log(method); //sceneScript.GetMethod(options[0].func).Invoke(null, null); //sceneScript.GetMethod(options[0].func).Invoke(null, null); //newCanvas.AddComponent< sceneScript.GetType() > ();//add NewGame script to canvas -- need to replace with generic //GameObject title = new GameObject("text", typeof(Text)); //title.transform.SetParent(newCanvas.transform); //title.AddComponent<Text>(); //title.GetComponent<Text>().text = menu.name; //title.GetComponent<Text>().font = Font.CreateDynamicFontFromOSFont("Ariel", 20); //Create title Text thetext = newCanvas.AddComponent <Text>(); thetext.transform.SetParent(newCanvas.transform); thetext.text = menu.name; thetext.font = Font.CreateDynamicFontFromOSFont("Ariel", 20); thetext.fontSize = 50; thetext.alignment = TextAnchor.UpperCenter;//center title Debug.Log(thetext.text); //create buttons GameObject tempButton; float y = 100.0f; //starting y value for buttons foreach (Option option in menu.options) //iterate through options and make a button for each one { tempButton = ButtonGenerator.GenerateButton(option.name); //create new Button tempButton.transform.SetParent(newCanvas.transform); //set new buttons parent canvas tempButton.transform.position = new Vector3(0.0f, y, 0.0f); y -= 50; //decrement y so each button is lower than the last //add onClick listener, needs to be made generic Button btn = tempButton.GetComponent <Button>(); //Debug.Log(btn); // Debug.Log(btn.onClick); // btn.onClick.AddListener(delegate { testClick(); }); //Debug.Log(btn.onClick); //btn.onClick.Invoke(); string function = option.func; //capture func //set onClick to lambda function that calls the method named in func btn.onClick.AddListener(() => { sceneScript.GetMethod(function).Invoke(null, null); }); //Debug.Log(tempButton.GetComponent<Button>()); //Debug.Log(tempButton.GetComponent<Button>().onClick); } }