Dictionary <InventoryItem, int> widgetDict; //字典? private void Start() { widgetStates = GetComponent <WidgetStates>(); widgetDict = new Dictionary <InventoryItem, int>(); widgetDict.Add(InventoryItem.ENERGPACK, 1); widgetDict.Add(InventoryItem.REPAIRKIT, 2); }
public void OnLeftMouseDown(MouseState mouseState) { if (!this.Visible) { return; } _state = WidgetStates.Pressed; }
/// <summary> /// Only used for loading the button from XML. /// </summary> internal Button() { _textures = new Texture2D[3]; _position = new Vector2(); _state = WidgetStates.Idle; this.ForeColor = Color.Black; this.Selectable = false; this.Visible = true; this.ZOrder = 1; this.Origin = Vector2.Zero; }
public Picture(Texture2D sprite) { this.Visible = true; this.Origin = Vector2.Zero; this.Sprite = sprite; this.Scale = new Vector2(1f); _previousState = WidgetStates.Idle; this.Selectable = false; _area = new Rectangle((int)this.Position.X, (int)this.Position.Y, (int)(this.Sprite.Width), (int)(this.Sprite.Height)); }
public void OnMouseHover(MouseState mouseState) { if (_previousState == WidgetStates.Pressed) { this.Clicked?.Invoke(this, new WidgetClickedEventArgs(_previousPressedButton)); } else { this.Mouse_Hover?.Invoke(this, new EventArgs()); } _previousState = WidgetStates.Hover; }
public void Update(GameTime gameTime) { if (!this.Visible) { return; } if (!this.Contains(Mouse.GetState().Position)) { _state = WidgetStates.Idle; } else if (_state != WidgetStates.Pressed && _state != WidgetStates.Hover) { _state = WidgetStates.Hover; } }
public void Update(GameTime gameTime) { if (!this.Contains(Mouse.GetState().Position)) { _previousState = WidgetStates.Idle; if (_mouseWithin) { this.Mouse_Left?.Invoke(this, new EventArgs()); } } else if (_previousState != WidgetStates.Pressed) { _previousState = WidgetStates.Hover; } }
public void OnMouseHover(MouseState mouseState) { if (!this.Visible) { return; } if (_state == WidgetStates.Pressed) { this.Value = !this.Value; this.Clicked?.Invoke(this, new WidgetClickedEventArgs(MouseButtons.Left)); _state = WidgetStates.Hover; } }
public virtual void UpdateStyle() { if (Enabled) { if (IsFocused) { WidgetState = WidgetStates.Active; } else if (Selected) { WidgetState = WidgetStates.Selected; } else { WidgetState = WidgetStates.Default; } } else { WidgetState = WidgetStates.Disabled; } }
private void Start() { widgetStates = GameObject.FindWithTag("Player").GetComponent <WidgetStates>(); isActivePT = firstPT; }
public GraphicalWidgetState(string name, WidgetStates widgetState) { Name = name; WidgetState = widgetState; }
public override void OnPaint(IGUIContext ctx, RectangleF bounds) { base.OnPaint(ctx, bounds); float lineHeight = LineHeight; float separatorHeight = SeparatorHeight; RectangleF rLine = bounds; rLine.Height = lineHeight; rLine.Width -= Padding.Right; rLine.Offset(0, Padding.Top); float textOffset = lineHeight + Padding.Left; bool buildTree = false; if (lastBounds != bounds || Tree == null) { try { lastBounds = bounds; Tree = new QuadTree(bounds); itemStartPositions = new float[Menu.Count]; buildTree = true; } catch (Exception ex) { ex.LogError(); } } for (int i = 0; i < Menu.Children.Count; i++) { IGuiMenuItem item = Menu.Children [i]; float itemHeight = 0; if (item.IsSeparator) { itemHeight = separatorHeight; float y = rLine.Y + separatorHeight / 2; using (Pen pen = new Pen(Theme.Colors.Base02, ScaleFactor)) ctx.DrawLine(pen, rLine.X + textOffset, y, rLine.X + rLine.Width, y); y++; using (Pen pen = new Pen(Theme.Colors.Base0, ScaleFactor)) ctx.DrawLine(pen, rLine.X + textOffset, y, rLine.X + rLine.Width, y); } else { itemHeight = lineHeight; WidgetStates state = WidgetStates.Default; if (!item.Enabled) { state = WidgetStates.Disabled; } else if (item == m_ActiveItem) { if (IsFocused || Selected) { state = WidgetStates.Active; } else { state = WidgetStates.Selected; } ctx.FillRectangle(Styles.GetStyle(state).BackColorBrush, new RectangleF(rLine.X + 1, rLine.Y, rLine.Width + Padding.Right - 2, rLine.Height)); } IWidgetStyle style = Styles.GetStyle(state); if (IconFont != null) { char icon; if (item.IsToggleButton) { icon = item.Checked ? (char)FontAwesomeIcons.fa_toggle_on : (char)FontAwesomeIcons.fa_toggle_off; } else { icon = (char)item.ImageIndex; } if (icon > 0) { RectangleF rIcon = rLine; rIcon.Width = lineHeight; ctx.DrawString(icon.ToString(), IconFont, style.ForeColorBrush, rIcon, FontFormat.DefaultIconFontFormatCenter); } } if (Font != null) { RectangleF rText = new RectangleF(rLine.X + textOffset, rLine.Y + 1, rLine.Width - textOffset, rLine.Height - 1); ctx.DrawString(item.Text, Font, style.ForeColorBrush, rText, FontFormat.DefaultMnemonicLine); if (item.HasChildren) { if (IconFont != null) { ctx.DrawString(((char)FontAwesomeIcons.fa_caret_right).ToString(), IconFont, style.ForeColorBrush, rText, FontFormat.DefaultSingleLineFar); } } else { string modifier = ModifierString(item); if (modifier != null) { ctx.DrawString(modifier, Font, style.ForeColorBrush, rText, FontFormat.DefaultSingleLineFar); } } } } if (buildTree) { try { Tree.Add(new LayoutItem(rLine, item)); itemStartPositions[i] = rLine.Y; } catch (Exception ex) { ex.LogError(); } } rLine.Offset(0, itemHeight); } }
public void OnLeftMouseDown(MouseState mouseState) { _previousState = WidgetStates.Pressed; _previousPressedButton = MouseButtons.Left; }
private void OnTriggerEnter(Collider other) { widgetStates = GameObject.FindWithTag("Player").GetComponent <WidgetStates>(); widgetStates.ApplayDamage(damageValue); Debug.Log("我是水,你碰到我会死的!"); }
private void Awake() { controller = GetComponent <CharacterController>(); m_WidgetStates = GetComponent <WidgetStates>(); }
public IWidgetStyle this[WidgetStates state] { get { return(GetStyle(state)); } set { SetStyle(value, state); } }
public IWidgetStyle GetStyle(WidgetStates state) { return(Styles[(int)state] ?? Styles [0]); }
public void SetStyle(IWidgetStyle style, WidgetStates state) { Styles[(int)state] = style; }
public override void OnPaint(IGUIContext ctx, RectangleF bounds) { float x = bounds.Left; float y = Padding.Top; float line = 0; float lineHeight = LineHeight; //int lineHeight = Bounds.Height; bool buildTree = false; if (lastBounds != bounds || Tree == null) { try { lastBounds = bounds; Tree = new QuadTree(bounds); itemStartPositions = new float[Menu.Count]; buildTree = true; } catch (Exception ex) { ex.LogError(); } } for (int i = 0; i < Menu.Children.Count; i++) { IGuiMenuItem item = Menu.Children [i]; if (item == null || !item.Visible) { continue; } float iconWidth = 0; float textWidth = 0; if (IconFont != null && item.ImageIndex > 0) { iconWidth = IconFont.Measure(((char)item.ImageIndex).ToString()).Width; } if (Font != null) { textWidth = Font.MeasureMnemonicString(item.Text).Width; if (textWidth > 0) { iconWidth *= 1.35f; } } float itemWidth = iconWidth + textWidth + Padding.Width; if (x + itemWidth > bounds.Width) { line++; x = bounds.Left; y += lineHeight; } RectangleF itemBounds = new RectangleF(x, y, itemWidth, lineHeight - Padding.Height); if (buildTree) { try { Tree.Add(new LayoutItem(itemBounds, item)); itemStartPositions[i] = itemBounds.X; } catch (Exception ex) { ex.LogError(); } } WidgetStates state = WidgetStates.Default; if (!item.Enabled) { state = WidgetStates.Disabled; } else if (item == ActiveItem) { if (IsFocused || Selected) { state = WidgetStates.Active; } else { state = WidgetStates.Selected; } ctx.FillRectangle(Styles.GetStyle(state).BackColorBrush, // irgendjemand scheint den mit bereits abgezogenem Padding aufzurufen, was falsch wäre new RectangleF(itemBounds.X, itemBounds.Y - Padding.Top, itemBounds.Width, itemBounds.Height + Padding.Height)); } Brush brush = Styles.GetStyle(state).ForeColorBrush; itemBounds.Offset(Padding.Left, 1); itemBounds.Width -= Padding.Left; if (iconWidth > 0) { ctx.DrawString(((char)item.ImageIndex).ToString(), IconFont, brush, itemBounds, FontFormat.DefaultIconFontFormatLeft); itemBounds.Offset((int)iconWidth, 0); } if (textWidth > 0) { ctx.DrawString(item.Text, Font, brush, itemBounds, FontFormat.DefaultMnemonicLine); } x += itemWidth; if (x > bounds.Width) { line++; x = bounds.Left; y += lineHeight; } } }
public bool HasStyle(WidgetStates state) { return(Styles[(int)state] != null); }