/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { Rectangle sRect = new Rectangle(); Rectangle dRect = new Rectangle(); graphics.GraphicsDevice.Clear(Color.CornflowerBlue); map.Draw(sprite, mapsTex, scroll); //if (drawType == DRAW_COL) DrawGrid(); DrawLedges(); sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); Color oColor = new Color(new Vector4(1.0f, 1.0f, 1.0f, 0.3f)); sprite.Draw(nullTex, new Rectangle(100, 50, 400, 1), oColor); sprite.Draw(nullTex, new Rectangle(100, 50, 1, 500), oColor); sprite.Draw(nullTex, new Rectangle(500, 50, 1, 500), oColor); sprite.Draw(nullTex, new Rectangle(100, 550, 400, 1), oColor); sprite.Draw(nullTex, new Rectangle(100, 300, 400, 1), oColor); sprite.End(); String layerName = "map"; switch (curLayer) { case 0: layerName = "back"; break; case 1: layerName = "mid"; break; case 2: layerName = "fore"; break; } if (text.DrawClickText(5, 5, "layer: " + layerName, mosX, mosY, mouseClick)) { curLayer = (curLayer + 1) % 3; } switch (drawType) { case DRAW_SELECT: layerName = "select"; break; case DRAW_COL: layerName = "col"; break; case DRAW_LEDGE: layerName = "ledge"; break; case DRAW_SCRIPT: layerName = "script"; break; } if (text.DrawClickText(5, 25, "draw: " + layerName, mosX, mosY, mouseClick)) { drawType = (drawType + 1) % 4; } if (drawType == DRAW_SCRIPT) { sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); sprite.Draw(nullTex, new Rectangle(400, 20, 400, 565), new Color( new Vector4(0f, 0f, 0f, .62f))); sprite.End(); for (int i = scriptScroll; i < scriptScroll + 28; i++) { if (selScript == i) { text.SetColor(Color.White); text.DrawText(405, 25 + (i - scriptScroll) * 20, i.ToString() + ": " + map.script[i] + "*"); } else { if (text.DrawClickText(405, 25 + (i - scriptScroll) * 20, i.ToString() + ": " + map.script[i], mosX, mosY, mouseClick)) { selScript = i; editingText = EDITING_SCRIPT; } } if (map.script[i].Length > 0) { String[] split = map.script[i].Split(' '); int c = GetCommandColor(split[0]); if (c > COLOR_NONE) { switch (c) { case COLOR_GREEN: text.SetColor(Color.Lime); break; case COLOR_YELLOW: text.SetColor(Color.Yellow); break; } text.DrawText(405, 25 + (i - scriptScroll) * 20, i.ToString() + ": " + split[0]); } } text.SetColor(Color.White); text.DrawText(405, 25 + (i - scriptScroll) * 20, i.ToString() + ": "); } if (drawButton(770, 20, 1, mosX, mosY, mouseDown) && scriptScroll > 0) { scriptScroll--; } if (drawButton(770, 550, 2, mosX, mosY, mouseDown) && scriptScroll < map.script.Length - 28) { scriptScroll++; } } if (drawType == DRAW_LEDGE) { for (int i = 0; i < 16; i++) { int y = 50 + i * 20; if (curLedge == i) { text.SetColor(Color.Lime); text.DrawText(520, 50 + i * 20, "ledge " + i.ToString()); } else { if (text.DrawClickText(520, 50 + i * 20, "ledge " + i.ToString(), mosX, mosY, mouseClick)) { curLedge = i; } } text.SetColor(Color.White); text.DrawText(620, 50 + i * 20, "n" + map.GetLedgeTotalNodes(i).ToString()); if (text.DrawClickText(680, 50 + i * 20, "f" + map.GetLedgeFlags(i).ToString(), mosX, mosY, mouseClick)) { map.SetLedgeFlags(i, (map.GetLedgeFlags(i) + 1) % 2); } } } text.SetColor(Color.White); if (editingText == EDITING_PATH) { text.DrawText(5, 45, map.path + "*"); } else { if (text.DrawClickText(5, 45, map.path, mosX, mosY, mouseClick)) { editingText = EDITING_PATH; } } if (drawButton(5, 65, 3, mosX, mosY, mouseClick)) { map.Write(); map.Write(true); } if (drawButton(40, 65, 4, mosX, mosY, mouseClick)) { map.Read(); } for (int i = selScroll; i < selScroll + 20; i++) { if (map.GetSegIdx(curLayer, i) > -1) { SegmentDefinition segDef = map.GetSegDef(map.GetSegIdx(curLayer, i)); if (selIdx == i) { text.SetColor(Color.Lime); text.DrawText(5, 100 + (i - selScroll) * 16, segDef.GetName()); } else { if (text.DrawClickText( 5, 100 + (i - selScroll) * 16, segDef.GetName(), mosX, mosY, mouseClick)) { selIdx = i; } } } } if (drawButton(100, 100, 1, mosX, mosY, mouseDown)) { if (selScroll > 0) { selScroll--; } } if (drawButton(100, 500, 2, mosX, mosY, mouseDown)) { if (selScroll < 43) { selScroll++; } } if (drawButton(5, 500, 1, mosX, mosY, mouseDown)) { if (selIdx > 0) { map.SwapSegs(curLayer, selIdx, selIdx - 1); selIdx--; } } if (drawButton(25, 500, 2, mosX, mosY, mouseDown)) { if (selIdx < 63) { map.SwapSegs(curLayer, selIdx, selIdx + 1); selIdx++; } } if (drawType == DRAW_SELECT) { sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); sprite.Draw(nullTex, new Rectangle(500, 20, 280, 550), new Color( new Vector4(0.0f, 0.0f, 0.0f, 0.4f))); sprite.End(); for (int i = segScroll; i < segScroll + 9; i++) { SegmentDefinition segDef = map.GetSegDef(i); if (segDef != null) { sprite.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); dRect.X = 500; dRect.Y = 50 + (i - segScroll) * 60; sRect = segDef.GetSrcRect(); if (sRect.Width > sRect.Height) { dRect.Width = 45; dRect.Height = (int)(((float)sRect.Height / (float)sRect.Width) * 45.0f); } else { dRect.Height = 45; dRect.Width = (int)(((float)sRect.Width / (float)sRect.Height) * 45.0f); } sprite.Draw(mapsTex[map.GetSegDef(i).GetSrcIdx()], dRect, sRect, Color.White); sprite.End(); text.SetSize(0.5f); text.SetColor(Color.White); text.DrawText(dRect.X + 50, dRect.Y, segDef.GetName()); if (mouseDown) { if (mosX > dRect.X && mosX < 700 && mosY > dRect.Y && mosY < dRect.Y + 45) { if (mouseDragSeg == -1) { int f = map.AddSeg(curLayer, i); if (f > -1) { float layerScalar = 0.5f; if (curLayer == 0) { layerScalar = 0.375f; } if (curLayer == 2) { layerScalar = 0.675f; } map.SetSegLoc(curLayer, f, new Vector2((float)(mosX - sRect.Width / 4 + scroll.X * layerScalar), (float)(mosY - sRect.Height / 4 + scroll.Y * layerScalar))); mouseDragSeg = f; pMosX = mosX; pMosY = mosY; } } } } } } if (drawButton(740, 20, 1, mosX, mosY, mouseDown)) { if (segScroll > 0) { segScroll--; } } if (drawButton(740, 550, 2, mosX, mosY, mouseDown)) { if (segScroll < 80) { segScroll++; } } } Vector2 v = new Vector2((float)mosX, (float)mosY) + scroll / 2.0f; v *= 2f; text.SetSize(.5f); text.SetColor(Color.White); text.DrawText(5, 580, ((int)v.X).ToString() + ", " + ((int)v.Y).ToString()); DrawCursor(); mouseClick = false; base.Draw(gameTime); }
private void DrawMapSegments() { var dRect = new Rectangle(); _text.Size = 0.8f; _spriteBatch.Begin(); _spriteBatch.Draw(_nullTex, new Rectangle(500, 20, 280, 550), new Color(0, 0, 0, 100)); _spriteBatch.End(); for (var i = 0; i < 9; i++) { var segDef = _map.SegmentDefinitions[i]; if (segDef == null) { continue; } _spriteBatch.Begin(); dRect.X = 500; dRect.Y = 50 + i * 60; var sRect = segDef.SourceRect; if (sRect.Width > sRect.Height) { dRect.Width = 45; dRect.Height = (int)((sRect.Height / (float)sRect.Width) * 45.0f); } else { dRect.Height = 45; dRect.Width = (int)((sRect.Width / (float)sRect.Height) * 45.0f); } _spriteBatch.Draw(_mapsTex[segDef.SourceIndex], dRect, sRect, Color.White ); _spriteBatch.End(); _text.Color = Color.White; _text.DrawText(dRect.X + 50, dRect.Y, segDef.Name); if (_rightMouseDown) { if (_mosX > dRect.X && _mosX < 780 && _mosY > dRect.Y && _mosY < dRect.Y + 45) { if (_mouseDragSeg == -1) { var f = _map.AddSeg(_curLayer, i); if (f <= -1) { continue; } var layerScalar = 0.5f; if (_curLayer == 0) { layerScalar = 0.375f; } else if (_curLayer == 2) { layerScalar = 0.625f; } _map.Segments[_curLayer, f].Location.X = (_mosX - sRect.Width / 4 + _scroll.X * layerScalar); _map.Segments[_curLayer, f].Location.Y = (_mosY - sRect.Height / 4 + _scroll.Y * layerScalar); _mouseDragSeg = f; } } } } }