private void actTokEditBtn_Click(object sender, EventArgs e) { int curSelectedIndex = activeTokensList.SelectedIndex; // No token selected if (curSelectedIndex < 0) { MessageBox.Show("No token selected.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MapToken selectedToken = (MapToken)activeTokensList.Items[curSelectedIndex]; TokenData tokenData = selectedToken.GetTokenData(); EditTokenForm charForm = new EditTokenForm(gameState); charForm.SetTokenData(ref tokenData); DialogResult result = charForm.ShowDialog(this); if (result == DialogResult.OK) { tokenData = charForm.GetTokenData(); selectedToken.SetTokenData(ref tokenData); } }
private void refreshActiveTokenList() { MapToken selectedToken = null; if (tokenLibList.SelectedIndex >= 0) { selectedToken = (MapToken)activeTokensList.SelectedItem; } activeTokensList.Items.Clear(); var enumerator = gameState.ActiveTokens.GetEnumerator(); while (enumerator.MoveNext()) { MapToken token = enumerator.Current; if (token.TokenType == TokenType.Player && activeTokPlayerFilterCheck.Checked) { activeTokensList.Items.Add(token); } else if (token.TokenType == TokenType.Enemy && activeTokEnemyFilterCheck.Checked) { activeTokensList.Items.Add(token); } else if (token.TokenType == TokenType.NPC && activeTokNonPlayerFilterCheck.Checked) { activeTokensList.Items.Add(token); } } activeTokensList.SelectedItem = selectedToken; }
public ViewStatsForm(MapToken mapToken, Point formPos) { InitializeComponent(); this.mapToken = mapToken; this.formPos = formPos; }
// Copy constructor public MapToken(MapToken other) { TokenData otherTokenData = other.GetTokenData(); this.mapCtrl = other.mapCtrl; this.tokenData = new TokenData(ref otherTokenData); this.position = other.Position; }
// Called when a token is added or removed from the collection protected void onMapTokenAddedRemoved(MapToken token) { MapTokenAddedRemovedEventHandler handler = MapTokenAddedRemovedEvent; if (handler != null) { MapTokenAddedRemovedEventArgs args = new MapTokenAddedRemovedEventArgs(token); handler(this, args); } }
public bool Remove(MapToken token) { int index = mapTokenList.IndexOf(token); if (index == -1) { return(false); } return(Remove(index)); }
// updates the mouse state of any active tokens on the map // depending on the current mouse position protected void updateActiveTokenMouseState(Point mousePos) { // No active tokens? Return if (gameState.ActiveTokens.Count == 0) { return; } // Get unit rectangle for current view RectangleF viewPortRect = GetViewportUnitRect(); MapToken tokenUnderMouse = null; // Loop through each active token foreach (MapToken token in gameState.ActiveTokens) { // Is a token currently being dragged? if (draggedToken != null) { if (token != draggedToken) { token.MouseState = TokenMouseState.Idle; } } else { RectangleF tokenUnitRect = token.GetUnitRect(); // Get unit rectangle for token Rectangle pixelRect = UnitRectToPixelRect(tokenUnitRect, viewPortRect); // Convert unit rect to pixel coordinates // If token is under mouse, set Hover state if (pixelRect.Contains(mousePos)) { token.MouseState = TokenMouseState.Hover; tokenUnderMouse = token; } else { token.MouseState = TokenMouseState.Idle; } } } if (tokenUnderMouse != null && !tokenHoverToolTip.Active) { TokenData data = tokenUnderMouse.GetTokenData(); tokenHoverToolTip.SetTokenData(ref data); tokenHoverToolTip.Active = true; } else if (tokenUnderMouse == null && tokenHoverToolTip.Active) { tokenHoverToolTip.Active = false; tokenHoverToolTip.Hide(this); } }
// User let go of the mouse button private void MapControl_MouseUp(object sender, MouseEventArgs e) { if (draggedToken != null) { draggedToken.MouseState = TokenMouseState.Hover; draggedToken = null; } leftMouseDown = false; refreshIfNeeded(); }
private void duplicateTokenToolStripMenuItem_Click(object sender, EventArgs e) { if (rightClickedToken == null) { return; } MapToken duplicateToken = new MapToken(rightClickedToken); gameState.ActiveTokens.Add(duplicateToken); Refresh(); }
public bool Add(MapToken token) { if (mapTokenList.Contains(token)) { return(false); } mapTokenList.Add(token); onMapTokenAddedRemoved(token); return(true); }
private void MapControl_MouseClick(object sender, MouseEventArgs e) { mouseDownTimer.Stop(); if (mouseDownTimer.ElapsedMilliseconds <= SELECT_TIME_FRAME) { MapToken mapToken = getTokenUnderMouse(e.Location); if (mapToken != null) { mapToken.Selected = !mapToken.Selected; } } refreshIfNeeded(); }
private void actTokRemoveBtn_Click(object sender, EventArgs e) { int curSelectedIndex = activeTokensList.SelectedIndex; // No token selected if (curSelectedIndex < 0) { MessageBox.Show("No token selected.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MapToken selectedToken = (MapToken)activeTokensList.Items[curSelectedIndex]; gameState.ActiveTokens.Remove(selectedToken); }
private void actTokLocateBtn_Click(object sender, EventArgs e) { int curSelectedIndex = activeTokensList.SelectedIndex; // No token selected if (curSelectedIndex < 0) { MessageBox.Show("No token selected.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MapToken selectedToken = (MapToken)activeTokensList.Items[curSelectedIndex]; mapControl.ViewPosition = selectedToken.Position; }
public bool Remove(int index) { if (index < 0 || index >= mapTokenList.Count) { return(false); } MapToken removed = mapTokenList[index]; mapTokenList.RemoveAt(index); onMapTokenAddedRemoved(removed); return(true); }
private void placeTokenOnMapBtn_Click(object sender, EventArgs e) { int curSelectedIndex = tokenLibList.SelectedIndex; if (curSelectedIndex < 0) { MessageBox.Show("No token selected.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } TokenData selectedToken = gameState.TokenLibrary[(string)tokenLibList.SelectedItem]; MapToken newToken = new MapToken(mapControl, ref selectedToken, mapControl.ViewPosition); // Make sure token is within the map bounds newToken.Position = newToken.Position; gameState.ActiveTokens.Add(newToken); }
public TokenListItemControl(MapToken token) { InitializeComponent(); this.token = token; this.data = token.GetTokenData(); TokenName.Text = data.Name; ACLabel.Text = "AC: " + data.ArmorClass; TokenStrength.Text = "STR: " + data.Strength; TokenDexterity.Text = "DEX: " + data.Dexterity; TokenConstitution.Text = "CON: " + data.Constitution; TokenIntelligence.Text = "INT: " + data.Intelligence; TokenWisdom.Text = "WIS: " + data.Wisdom; TokenCharisma.Text = "CHA: " + data.Charisma; HealthBox.Text = data.CurrentHP + " / " + data.MaxHP; if (data.CurrentHP >= data.MaxHP / 3) { HealthBox.BackColor = Color.Lime; } else if (data.CurrentHP >= data.MaxHP / 10) { HealthBox.BackColor = Color.Orange; } else { HealthBox.BackColor = Color.Red; } }
// User clicked the map. // Remember that mouse position for later use // when calculating map drag offset private void MapControl_MouseDown(object sender, MouseEventArgs e) { MapToken tokenUnderMouse = getTokenUnderMouse(e.Location); mouseDownPos = e.Location; mouseDownTimer.Reset(); mouseDownTimer.Start(); if (e.Button == MouseButtons.Left) { leftMouseDown = true; if (tokenUnderMouse != null) { tokenUnderMouse.MouseState = TokenMouseState.Drag; this.draggedToken = tokenUnderMouse; this.mouseDragState = MouseDragState.Token; } else { this.mouseDragState = MouseDragState.Map; } } else if (e.Button == MouseButtons.Right) { if (tokenUnderMouse != null) { rightClickedToken = tokenUnderMouse; tokenContextMenu.Show(this, e.Location); } else { rightClickedToken = null; mapContextMenu.Show(this, e.Location); } } refreshIfNeeded(); }
public MapTokenAddedRemovedEventArgs(MapToken token) { this.token = token; }
// Checks if MapToken instance is in collection public bool Contains(MapToken mapToken) { return(mapTokenList.Contains(mapToken)); }
// returns index by data public int IndexOf(MapToken token) { return(mapTokenList.IndexOf(token)); }