private void CharPanel_MouseMove(object sender, MouseEventArgs e) { coveredUnit = null; int index = findRectangle(e.X, e.Y); if (index >= 0) { if (units[index] != null) { this.Cursor = Cursors.Hand; coveredUnit = units[index]; editor.currentName.Text = coveredUnit.Item.Name; } else { editor.currentName.Text = "None"; this.Cursor = Cursors.Cross; curUnit.X = index; curUnit.Y = 1; } } else { curUnit.Y = -1; editor.currentName.Text = "None"; } this.Invalidate(); }
private void CharPanel_MouseLeave(object sender, EventArgs e) { curUnit.Item = null; coveredUnit = null; this.Invalidate(); }
public bool loadItemsByCodes(byte[] codes, int offset, int len) { // if (offset < 0 || len < xnum * ynum * EquipItem.ITEM_SIZE || codes == null) { this.Invalidate(); return(false); } EquipItem item = null; for (int j = 0; j < ynum; j++) { for (int i = 0; i < xnum; i++) { if ((item = EquipItem.createItem(codes, offset + (j * xnum + i) * EquipItem.ITEM_SIZE, EquipItem.ITEM_SIZE)) != null) { units[i, j] = new DrawingUnit(item, i, j); putItem(units[i, j], false); } } } this.Invalidate(); return(true); }
public bool canPutItem(DrawingUnit unit) { EquipItem item = unit.Item; int x = unit.X, y = unit.Y; if (item.Width + x > xnum || item.Height + y > ynum || x < 0 || y < 0) { return(false); } if (flags[x, y]) { return(false); } for (int i = 0; i < item.Width; i++) { for (int j = 0; j < item.Height; j++) { if (flags[i + x, j + y]) { return(false); } } } return(true); }
public bool putItem(EquipItem item, bool add) { DrawingUnit unit = null; if (add) { unit = new DrawingUnit(new EquipItem(), 0, 0); unit.Item.assign(item); } else { unit = new DrawingUnit(item, 0, 0); } for (int j = 0; j < ynum; j++) { for (int i = 0; i < xnum; i++) { if (!flags[i, j]) { unit.X = i; unit.Y = j; if (canPutItem(unit)) { return(putItem(unit, false)); } } } } return(false); }
public bool putItem(DrawingUnit unit, bool add) { try { int x = unit.X, y = unit.Y; if (add) { units[x, y] = new DrawingUnit(new EquipItem(), x, y); units[x, y].Item.assign(unit.Item); } else { units[x, y] = unit; } for (int i = 0; i < unit.Item.Width; i++) { for (int j = 0; j < unit.Item.Height; j++) { flags[i + x, j + y] = true; } } return(true); } catch (Exception ex) { MessageBox.Show("Error: On item:" + unit.Item.Name + ", X:" + unit.X + ", Y: " + unit.Y + " " + ex.Message); return(false); } }
private void EquipPanel_MouseMove(object sender, MouseEventArgs e) { int x = e.X / pixels, y = e.Y / pixels; coveredUnit = null; if (activeUnit != null) { activeUnit.X = x; activeUnit.Y = y; } else if (flags[x, y]) { this.Cursor = Cursors.Hand; coveredUnit = findUnit(x, y); editor.currentName.Text = coveredUnit.Item.Name; if (selectedUnit == coveredUnit) { coveredUnit = null; } } else { this.Cursor = Cursors.Cross; curUnit.X = x; curUnit.Y = y; editor.currentName.Text = "None"; } this.Invalidate(); }
public bool removeItem(DrawingUnit unit) { int x = unit.X; units[x] = null; //remove return(true); }
private void setEquipProperty(DrawingUnit unit) { if (unit != null) // { EquipProperty prop = new EquipProperty(unit.Item); prop.ShowDialog(); prop.Dispose(); } }
public void clearData() { selectedUnit = null; coveredUnit = null; for (int i = 0; i < EquipNum; i++) { units[i] = null; } }
private void CharPanel_KeyDown(object sender, KeyEventArgs e) { if (selectedUnit != null) { switch ((int)e.KeyCode) { case 46: // Delete removeItem(selectedUnit); selectedUnit = null; break; } } }
/// <summary> /// /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EquipPanel_KeyDown(object sender, KeyEventArgs e) { if (selectedUnit != null) { switch ((int)e.KeyCode) { case 46: removeItem(selectedUnit); selectedUnit = null; Invalidate(); break; } } }
private void drawUnit(Graphics g, DrawingUnit unit) { int x = unit.X, y = unit.Y; EquipItem item = unit.Item; int xOffset = Math.Max((positions[x].Width - item.Width * EquipPanel.pixels) >> 1, 0); int yOffset = Math.Max((positions[x].Height - item.Height * EquipPanel.pixels) >> 1, 0); int width = Math.Min(item.Width * EquipPanel.pixels, positions[x].Width); int height = Math.Min(item.Height * EquipPanel.pixels, positions[x].Height); g.DrawImage(item.Img, positions[x].X + xOffset, positions[x].Y + yOffset, width, height); }
public bool canPutItem(DrawingUnit unit) { EquipItem item = unit.Item; int x = unit.X, y = unit.Y; if (x < 0 && x >= EquipNum && units[x] != null) { return(false); } return(true); }
private void CharPanel_MouseClick(object sender, MouseEventArgs e) { int index = findRectangle(e.X, e.Y); if (e.Button == MouseButtons.Right) { if (index >= 0) { if (units[index] != null) { selectedUnit = units[index]; popMenu.Show(this, e.X, e.Y); } else { selectedUnit = null; } } else { selectedUnit = null; } } else { if (index >= 0) { if (units[index] != null) { selectedUnit = units[index]; editor.currentName.Text = selectedUnit.Item.Name; } else if (selectedUnit != null) { selectedUnit = null; editor.currentName.Text = "None"; } else { addEditItem(index); editor.currentName.Text = "None"; } } else { selectedUnit = null; } } }
public void clearData() { activeUnit = null; selectedUnit = null; coveredUnit = null; lastedX = 0; lastedY = 0; for (int i = 0; i < xnum; i++) { for (int j = 0; j < ynum; j++) { units[i, j] = null; flags[i, j] = false; } } }
public bool putItem(DrawingUnit unit, bool add) { int x = unit.X, y = unit.Y; if (add) { units[x] = new DrawingUnit(new EquipItem(), x, y); units[x].Item.assign(unit.Item); } else { units[x] = unit; } return(true); }
private void drawUnit(Graphics g, DrawingUnit unit) { int x = unit.X, y = unit.Y; EquipItem item = unit.Item; g.DrawImage(item.Img, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); if (item.Level >= 1) { g.DrawString("+" + Convert.ToString(item.Level), new Font("Arial", 8), Brushes.White, x * pixels, y * pixels); } else if (item.IsNoDurability && item.Durability > 1) { g.DrawString(Convert.ToString(item.Durability), new Font("Arial", 6), Brushes.White, x * pixels, y * pixels); } }
private void EquipPanel_MouseLeave(object sender, EventArgs e) { curUnit.Item = null; coveredUnit = null; if (activeUnit != null) { activeUnit.X = lastedX; activeUnit.Y = lastedY; if (canPutItem(activeUnit) && putItem(activeUnit, false)) { selectedUnit = activeUnit; activeUnit = null; } } this.Invalidate(); }
protected DrawingUnit findUnit(int x, int y) { DrawingUnit unit = null; if (flags[x, y]) { for (int i = 0; i < xnum; i++) { for (int j = 0; j < ynum; j++) { if ((unit = units[i, j]) != null && unit.contains(x, y)) { return(unit); } } } } return(null); }
public bool loadItemsByCodes(byte[] codes, int offset, int len) { // if (offset < 0 || len < EquipItem.ITEM_SIZE * EquipNum || codes == null) { this.Invalidate(); return(false); } EquipItem item = null; for (int i = 0; i < EquipNum; i++) { if ((item = EquipItem.createItem(codes, offset + i * EquipItem.ITEM_SIZE, EquipItem.ITEM_SIZE)) != null) { units[i] = new DrawingUnit(item, i, 0); } } this.Invalidate(); return(true); }
public bool removeItem(DrawingUnit unit) { try { int x = unit.X, y = unit.Y; units[x, y] = null; //remove for (int i = 0; i < unit.Item.Width; i++) { for (int j = 0; j < unit.Item.Height; j++) { flags[i + x, j + y] = false; } } } catch (Exception) { } return(true); }
public bool moveItem(DrawingUnit unit, int x, int y) { if (null == unit || unit.Item == null) { return(false); } int oldX = unit.X, oldY = unit.Y; removeItem(unit); unit.X = x; unit.Y = y; if (canPutItem(unit) && putItem(unit, false)) { return(true); } else { unit.X = oldX; unit.Y = oldY; putItem(unit, false); return(false); } }
public bool loadItemsByCodes(byte[] codes, int offset, int len) { // if (offset < 0 || len < EquipItem.ITEM_SIZE * EquipNum || codes == null) { this.Invalidate(); return false; } EquipItem item = null; for (int i = 0; i < EquipNum; i++) { if ((item = EquipItem.createItem(codes, offset + i * EquipItem.ITEM_SIZE, EquipItem.ITEM_SIZE)) != null) { units[i] = new DrawingUnit(item, i, 0); } } this.Invalidate(); return true; }
public void assign(DrawingUnit unit) { x = unit.X; y = unit.Y; item = unit.Item; }
private void CharPanel_MouseMove(object sender, MouseEventArgs e) { coveredUnit = null; int index = findRectangle (e.X, e.Y); if (index >= 0) { if (units[index] != null) { this.Cursor = Cursors.Hand; coveredUnit = units[index]; editor.currentName.Text = coveredUnit.Item.Name; } else { editor.currentName.Text = "None"; this.Cursor = Cursors.Cross; curUnit.X = index; curUnit.Y = 1; } } else { curUnit.Y = -1; editor.currentName.Text = "None"; } this.Invalidate(); }
private void EquipPanel_Paint(object sender, PaintEventArgs e) { if (units == null) { return; } // Graphics g = e.Graphics; DrawingUnit unit = null; EquipItem item = null; int x = 0, y = 0; for (int i = 0; i < xnum; i++) { for (int j = 0; j < ynum; j++) { if ((unit = units[i, j]) != null && unit.Item != null) { drawUnit(g, units[i, j]); } } } if (null != selectedUnit && null != selectedUnit.Item) { Brush brush = new SolidBrush(Color.FromArgb(60, 128, 128, 128)); g.FillRectangle(brush, selectedUnit.X * pixels, selectedUnit.Y * pixels, selectedUnit.Item.Width * pixels, selectedUnit.Item.Height * pixels); } if (null != activeUnit && null != activeUnit.Item) { item = activeUnit.Item; x = activeUnit.X; y = activeUnit.Y; g.DrawImage(item.Img, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); if (canPutItem(activeUnit)) { g.DrawRectangle(Pens.Blue, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); } else { g.DrawRectangle(Pens.Red, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); } } if (coveredUnit != null && coveredUnit.Item != null) { item = coveredUnit.Item; x = coveredUnit.X; y = coveredUnit.Y; g.DrawRectangle(Pens.Blue, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); } if (activeUnit == null && coveredUnit == null && selectedUnit == null && curUnit != null && curUnit.Item != null) { item = curUnit.Item; x = curUnit.X; y = curUnit.Y; g.DrawImage(item.Img, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); if (canPutItem(curUnit)) { g.DrawRectangle(Pens.Blue, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); } else { g.DrawRectangle(Pens.Red, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); } } }
public bool removeItem(DrawingUnit unit) { try { int x = unit.X, y = unit.Y; units[x, y] = null; //remove for (int i = 0; i < unit.Item.Width; i++) { for (int j = 0; j < unit.Item.Height; j++) { flags[i + x, j + y] = false; } } } catch(Exception) { } return true; }
public bool moveItem(DrawingUnit unit, int x, int y) { if (null == unit || unit.Item == null) { return false; } int oldX = unit.X, oldY = unit.Y; removeItem(unit); unit.X = x; unit.Y = y; if (canPutItem(unit) && putItem(unit, false)) { return true; } else { unit.X = oldX; unit.Y = oldY; putItem(unit, false); return false; } }
public bool canPutItem(DrawingUnit unit) { EquipItem item = unit.Item; int x = unit.X, y = unit.Y; if (item.Width + x > xnum || item.Height + y > ynum || x < 0 || y < 0) return false; if (flags[x, y]) return false; for (int i = 0; i < item.Width; i++) { for (int j = 0; j < item.Height; j++) { if (flags[i + x, j + y]) return false; } } return true; }
private void drawUnit(Graphics g, DrawingUnit unit) { int x = unit.X, y = unit.Y; EquipItem item = unit.Item; g.DrawImage(item.Img, x * pixels, y * pixels, item.Width * pixels, item.Height * pixels); if (item.Level >= 1) { g.DrawString("+" + Convert.ToString(item.Level), new Font("Arial", 8), Brushes.White, x * pixels, y * pixels); } else if (item.IsNoDurability && item.Durability > 1) { g.DrawString (Convert.ToString(item.Durability), new Font("Arial", 6), Brushes.White, x * pixels, y * pixels); } }
public bool canPutItem(DrawingUnit unit) { EquipItem item = unit.Item; int x = unit.X, y = unit.Y; if (x < 0 && x >= EquipNum && units[x] != null) return false; return true; }
public bool putItem(DrawingUnit unit, bool add) { try { int x = unit.X, y = unit.Y; if (add) { units[x, y] = new DrawingUnit(new EquipItem(), x, y); units[x, y].Item.assign(unit.Item); } else { units[x, y] = unit; } for (int i = 0; i < unit.Item.Width; i++) { for (int j = 0; j < unit.Item.Height; j++) { flags[i + x, j + y] = true; } } return true; } catch (Exception ex) { MessageBox.Show("Error: On item:" + unit.Item.Name + ", X:" + unit.X + ", Y: " + unit.Y + " " + ex.Message); return false; } }
private void EquipPanel_MouseClick(object sender, MouseEventArgs e) { DrawingUnit unit = null; int x = e.X / pixels, y = e.Y / pixels; if (e.Button == MouseButtons.Right) { if (activeUnit != null) { activeUnit.X = lastedX; activeUnit.Y = lastedY; if (canPutItem(activeUnit) && putItem(activeUnit, false)) { selectedUnit = activeUnit; activeUnit = null; } } else if ((unit = findUnit(x, y)) != null) { selectedUnit = unit; popMenu.Show(this, e.X, e.Y); }else { selectedUnit = null; } } else { if (activeUnit == null) { if (!flags[x, y]) { if (selectedUnit == null) { editor.currentName.Text = "None"; addEditItem(x, y); } else { selectedUnit = null; editor.currentName.Text = "None"; } } else if ((unit = findUnit(x, y)) != null && unit == selectedUnit) { removeItem(selectedUnit); activeUnit = selectedUnit; lastedX = selectedUnit.X; lastedY = selectedUnit.Y ; selectedUnit = null; } else { selectedUnit = unit; editor.currentName.Text = selectedUnit.Item.Name; } } else { activeUnit .X = x; activeUnit .Y = y; if (canPutItem(activeUnit) && putItem (activeUnit, false)) { selectedUnit = activeUnit; activeUnit = null; } } } this.Invalidate(); }
private void EquipPanel_MouseClick(object sender, MouseEventArgs e) { DrawingUnit unit = null; int x = e.X / pixels, y = e.Y / pixels; if (e.Button == MouseButtons.Right) { if (activeUnit != null) { activeUnit.X = lastedX; activeUnit.Y = lastedY; if (canPutItem(activeUnit) && putItem(activeUnit, false)) { selectedUnit = activeUnit; activeUnit = null; } } else if ((unit = findUnit(x, y)) != null) { selectedUnit = unit; popMenu.Show(this, e.X, e.Y); } else { selectedUnit = null; } } else { if (activeUnit == null) { if (!flags[x, y]) { if (selectedUnit == null) { editor.currentName.Text = "None"; addEditItem(x, y); } else { selectedUnit = null; editor.currentName.Text = "None"; } } else if ((unit = findUnit(x, y)) != null && unit == selectedUnit) { removeItem(selectedUnit); activeUnit = selectedUnit; lastedX = selectedUnit.X; lastedY = selectedUnit.Y; selectedUnit = null; } else { selectedUnit = unit; editor.currentName.Text = selectedUnit.Item.Name; } } else { activeUnit.X = x; activeUnit.Y = y; if (canPutItem(activeUnit) && putItem(activeUnit, false)) { selectedUnit = activeUnit; activeUnit = null; } } } this.Invalidate(); }
public bool putItem(DrawingUnit unit, bool add) { int x = unit.X, y = unit.Y; if (add) { units[x] = new DrawingUnit(new EquipItem(), x, y); units[x].Item.assign(unit.Item); } else { units[x] = unit; } return true; }
public bool putItem(EquipItem item, bool add) { DrawingUnit unit = null; if (add) { unit = new DrawingUnit(new EquipItem(), 0, 0); unit.Item.assign(item); } else { unit = new DrawingUnit(item, 0, 0); } for (int j = 0; j < ynum; j++) { for (int i = 0; i < xnum; i++) { if (!flags[i, j]) { unit.X = i; unit.Y = j; if (canPutItem(unit)) { return putItem(unit, false); } } } } return false; }
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) { removeItem(selectedUnit); selectedUnit = null; }
public bool loadItemsByCodes(byte[] codes, int offset, int len) { // if (offset < 0 || len < xnum * ynum * EquipItem.ITEM_SIZE || codes == null) { this.Invalidate(); return false; } EquipItem item = null; for (int j = 0; j < ynum; j++) { for (int i = 0; i < xnum; i++) { if ((item = EquipItem.createItem(codes, offset + (j * xnum + i) * EquipItem.ITEM_SIZE, EquipItem.ITEM_SIZE)) != null) { units[i, j] = new DrawingUnit(item, i, j); putItem(units[i, j], false); } } } this.Invalidate(); return true; }
public bool removeItem(DrawingUnit unit) { int x = unit.X; units[x] = null; //remove return true; }