public Game(Canvas displayCanvas, Window applicationwindow) { GameLevel = 1; GameScore = 0; PlayerLives = 3; /* * this._Tiles = new string[][]{ * new string []{"1", "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "0" , "0" , "0" , "0" , "0" , "0" , "0" , "1" }, * new string []{"1", "1" , "1" , "1" , "1" , "1" , "1" , "1" , "1" }};*/ LoadLevel(); this._DisplayCanvas = displayCanvas; this._MapRenderer = new CanvasMapRenderer(this._DisplayCanvas, new Geom.Rectangle(0, 0, 88, 88)); this._Input = new Input(applicationwindow, _MapRenderer); this._Invalid = true; this._PlayerPosition = new Geom.Point(1, 1); Timer.Interval = new TimeSpan(0, 0, 0, 0, 24); Timer.Tick += new EventHandler(Update); Timer.Start(); }
public Input(Window applicationWindow, IMapRenderer maprenderer) { this._ApplicationWindow = applicationWindow; this._MapRenderer = maprenderer; this._ApplicationWindow.KeyDown += new KeyEventHandler(OnKeyButtonDown); this.NewDirection = Directions.NONE; }
public override void Initialize() { base.Initialize(); spriteBatch = new SpriteBatch(GraphicsDevice); mapRenderer = new LevelMapRenderer(GraphicsDevice); }
private void EnsureRenderWrapper() { if (_renderWrapper == null) { _renderWrapper = CreateMapRenderer(); } }
public void draw(IMapRenderer mapRenderer) { Color[] pix; pix = mapRenderer.getColors(); mapTexture.SetPixels(pix); mapTexture.Apply(); }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { if (key == Key.Root && !TileCache.ContainsKey(key)) { TileCache.Add(Key.Root, new TileData(new StandardBitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("TiledMaps.VirtualEarth.msvesatellite.png")))); } return(base.GetTile(key, renderer, callback, state)); }
public MapRenderHelper(IMapRenderer <TPin, TPolyline> renderer) { if (renderer == null) { throw new ArgumentNullException("renderer"); } _renderer = renderer; }
public MainWindowViewModel(IMapProvider mapProvider, IRouter router, IMapRenderer mapRenderer) { _mapProvider = mapProvider; _router = router; _mapRenderer = mapRenderer; PlanTripCommand = new YaCommand(_ => PlanTrip()); }
public MapController(IMapRenderer renderer) { Renderer = renderer ?? throw new ArgumentException(nameof(renderer)); Config = ConfigLoader.LoadConfig <MapConfig>("Village.Core.Map.Internal.MapConfig.json"); _layers = new Dictionary <string, IMapLayer>(); _mapStructs = new Dictionary <string, IMapStructure>(); BuildMap(); }
public void draw(IMapRenderer mapRenderer) { MeshRenderer mr = GetComponent <MeshRenderer>(); mr.enabled = true; Color[] pix; pix = mapRenderer.getColors(); mapTexture.SetPixels(pix); mapTexture.Apply(); }
void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable) { if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null) { return; } Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY); renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height)); }
public Game(Environment map, IMapRenderer renderer, IGameObjectOpener opener, IInputGetter inputGetter, IWithToDo withToDo) { this.startingMap = map; this.opener = opener; this.inputGetter = inputGetter; this.Renderer = renderer; DelegatesQueue dq = new DelegatesQueue(); this.uiDoThis = dq; withToDo.ToDo = dq; }
public MapRenderModule(IRenderQueue queue, IMapRenderer renderer, IJobPrioritizer prioritizer, IResultWriter writer, IResultReader reader, IConfigService config, IWorldFinder finder, IWorldArchivist archivist) { _queue = queue; _renderer = renderer; _prioritizer = prioritizer; _writer = writer; _reader = reader; _config = config; _finder = finder; _archivist = archivist; ensureOverviewerOutput(); }
public OpenWorldGameMode(ViewportAdapter viewPort, IPossibleMovements possibleMovements, string worldName, EntityManager entityManager, StoryEngine storyEngine, EventHandler clickEvent) : base(clickEvent) { _entityManager = entityManager; EntityRenderersDict = new Dictionary <Entity, AbstractEntityRenderer>(); _possibleMovements = possibleMovements; _content = ContentManagerFactory.RequestContentManager(); RenderList = new List <IRenderable>(); Map = _content.Load <TiledMap>($"TopDownRpg/{worldName}"); var graphics = StaticServiceLocator.GetService <GraphicsDevice>(); _mapRenderer = new FullMapRenderer(graphics); _mapRenderer.SwapMap(Map); _tileSize = new Vector2(Map.TileWidth, Map.TileHeight); _moverManager = new MoverManager(); var collisionSystem = new CompositeAbstractCollisionSystem(_possibleMovements); _expiringSpatialHash = new ExpiringSpatialHashCollisionSystem <Entity>(_possibleMovements); _spatialHashMover = new SpatialHashMoverManager <Entity>(collisionSystem, _expiringSpatialHash); AddPlayer(); var entityController = EntityControllerFactory.AddEntityController(PlayerEntity.Instance, _possibleMovements, _moverManager); var texture = _content.Load <Texture2D>("TopDownRpg/Path"); var endTexture = _content.Load <Texture2D>("TopDownRpg/BluePathEnd"); collisionSystem.AddCollisionSystem(new TiledCollisionSystem(_possibleMovements, Map, "Collision-Layer")); collisionSystem.AddCollisionSystem(_expiringSpatialHash); CollisionSystem = collisionSystem; AddClickController(PlayerEntity.Instance); PathRenderer = new PathRenderer(_moverManager, PlayerEntity.Instance, texture, endTexture, _tileSize.ToPoint(), Map.Width, Map.Height); UpdateList.Add(_expiringSpatialHash); UpdateList.Add(entityController); UpdateList.Add(_spatialHashMover); UpdateList.Add(_moverManager); CameraTracker = CameraTrackerFactory.CreateTracker(viewPort, EntityRenderersDict[PlayerEntity.Instance], Map); UpdateList.Add(CameraTracker); LoadEntities(); var dialogFont = _content.Load <SpriteFont>("dialog"); var settings = StaticServiceLocator.GetService <IControllerSettings>(); DialogBox = new EntityStoryBoxDialog(ScreenSize.Size, dialogFont, settings.GamePadEnabled); GuiManager.AddGuiLayer(DialogBox); storyEngine.LoadWorld(AddEntity, RemoveEntity, CollisionSystem.CheckMovementCollision, worldName); InteractEvent += (sender, args) => { var facingDirection = PlayerEntity.Instance.FacingDirection; var interactTarget = (PlayerEntity.Instance.Position + facingDirection).ToPoint(); Interact(interactTarget); }; AddInteractionController(); CameraController.AddCameraZoomController(CameraTracker, ClickController); CameraController.AddCameraMovementController(CameraTracker, ClickController); }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { TileData tileData = null; // try to get the tile if (TileCache.TryGetValue(key, out tileData)) return tileData; // check if it is in the file cache string tilePath = GetTilePathForKey(key); if (File.Exists(tilePath)) { FileInfo finfo = new FileInfo(tilePath); if (DateTime.Now - finfo.CreationTime > new TimeSpan(2, 0, 0, 0)) { // tile is old, expire it File.Delete(tilePath); } else { try { using (FileStream fstream = new FileStream(tilePath, FileMode.Open)) { IMapDrawable bitmap = renderer.GetBitmapFromStream(this, fstream); return TileCache[key] = new TileData(bitmap); } } catch (Exception) { File.Delete(tilePath); } } } // check if its a bad key Uri uri = GetUriForKey(key); if (uri != null) { // mark tile as being downloaded TileCache[key] = null; GetTileData data = new GetTileData(); data.Renderer = renderer; data.Key = key; data.Callback = callback; data.State = state; data.Uri = uri; //ThreadPool.QueueUserWorkItem(new WaitCallback(GetTile), data); GetTile(data); } return tileData; }
/// <summary> /// Does some initialization, called from constructor. /// </summary> private void Init() { mapRenderer = new VectorMapRenderer(new RenderConfiguration()); renderToCanvasTimer = new DispatcherTimer(); renderToCanvasTimer.Tick += RenderMapFromBufferToCanvas; renderToCanvasTimer.Interval = new TimeSpan(100); lastTimeCanvasRendered = 0; gameLoopStepTimer = new DispatcherTimer(); gameLoopStepTimer.Tick += PerformGameLoopStep; gameLoopStepTimer.Interval = new TimeSpan(100); lastTimeGameLoopStep = 0; startTime = DateTime.Now; ResumeGame(); }
public void LoadMap(ContentManager contentManager, int mapId) { _tiledMap = contentManager.Load <TiledMap>(String.Format("maps/map{0}", mapId)); _mapRenderer = new FullMapRenderer(SceneManager.Instance.GraphicsDevice, new MapRendererConfig { DrawObjectLayers = false }); _mapRenderer.SwapMap(_tiledMap); var blockedLayer = (TiledTileLayer)_tiledMap.GetLayer("Block"); if (blockedLayer == null) { return; } foreach (var tile in blockedLayer.Tiles) { if (tile.Id != 0) { _tileColliderBoxes.Add(new Rectangle(tile.X * (int)TileSize.X, tile.Y * (int)TileSize.Y, (int)TileSize.X, (int)TileSize.Y)); } } }
public Game( IRenderWindow renderWindow, IMapRenderer mapRenderer, IGameState gameState, IMouseInfoProvider mouseInfoProvider, IItemManager itemManager, ISessionManager sessionManager, ISoundProvider soundProvider, IMPQProvider mpqProvider, IGameHUD gameHUD ) { this.renderWindow = renderWindow; this._mapRenderer = mapRenderer; this.gameState = gameState; this.mouseInfoProvider = mouseInfoProvider; this.sessionManager = sessionManager; this.gameHUD = gameHUD; //var item = itemManager.getItem("hdm"); }
public abstract TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state);
public int DrawMap(IMapRenderer renderer, int x, int y, int width, int height, WaitCallback callback, object state) { int unavailable = 0; // approximate the the top left tile (it may be off by 1), but the loop // below will kept it from being drawn int midX = x + width / 2 - myCenterOffset.X; int midY = y + height / 2 - myCenterOffset.Y; int xTiles = (midX - x) / 256 + 1; int yTiles = (midY - y) / 256 + 1; Key currentXKey = new Key(myCenterTile.X - xTiles, myCenterTile.Y - yTiles, myZoom); int xStart = midX - xTiles * 256; int yStart = midY - yTiles * 256; Rectangle rect = new Rectangle(x, y, width, height); int tickCount = Environment.TickCount; for (int currentX = xStart; currentX < x + width; currentX += 256, currentXKey.X++) { Key key = currentXKey; for (int currentY = yStart; currentY < y + height; currentY += 256, key.Y++) { IMapDrawable tile = null; // find the intersect region of the tile that we are drawing Rectangle tileRect = new Rectangle(currentX, currentY, 256, 256); tileRect.Intersect(rect); Rectangle sourceRect = new Rectangle(tileRect.X - currentX, tileRect.Y - currentY, tileRect.Width, tileRect.Height); // dont draw off the map tiles if (!key.IsValid) { // dont draw gray rect if we're drawing transparent if (!HasAlpha) renderer.FillRectangle(BackColor, tileRect); continue; } // first try to get the tile from the tileData TileData tileData = GetTile(key, renderer, callback, state); if (tileData != null) { tile = tileData.Bitmap; tileData.LastUsed = tickCount; } if (tile == null) { // tile not available, so try to generate a tile from child tiles unavailable++; Key childKey = new Key(key.X * 2, key.Y * 2, key.Zoom + 1); Key tl = childKey; Key tr = new Key(childKey.X + 1, childKey.Y, childKey.Zoom); Key br = new Key(childKey.X + 1, childKey.Y + 1, childKey.Zoom); Key bl = new Key(childKey.X, childKey.Y + 1, childKey.Zoom); TileData tld; TileData trd; TileData bld; TileData brd; // see if the children are available // we also need to null check, because they could be loading if (TileCache.TryGetValue(tl, out tld) && TileCache.TryGetValue(tr, out trd) && TileCache.TryGetValue(br, out brd) && TileCache.TryGetValue(bl, out bld) && tld != null && trd != null && bld != null & brd != null && tld.Bitmap != null && trd.Bitmap != null && bld.Bitmap != null && brd.Bitmap != null) { // children are available, so mark them as recently used tld.LastUsed = trd.LastUsed = bld.LastUsed = brd.LastUsed = tickCount; // calculate the destination rects of each child tile Rectangle tlr = new Rectangle(currentX, currentY, 128, 128); Rectangle trr = new Rectangle(currentX + 128, currentY, 128, 128); Rectangle blr = new Rectangle(currentX, currentY + 128, 128, 128); Rectangle brr = new Rectangle(currentX + 128, currentY + 128, 128, 128); tlr.Intersect(rect); trr.Intersect(rect); blr.Intersect(rect); brr.Intersect(rect); // calculate the source rect of each child tile Rectangle tlsr = new Rectangle(tlr.X - currentX, tlr.Y - currentY, tlr.Width * 2, tlr.Height * 2); Rectangle trsr = new Rectangle(trr.X - currentX - 128, trr.Y - currentY, trr.Width * 2, trr.Height * 2); Rectangle blsr = new Rectangle(blr.X - currentX, blr.Y - currentY - 128, blr.Width * 2, blr.Height * 2); Rectangle brsr = new Rectangle(brr.X - currentX - 128, brr.Y - currentY - 128, brr.Width * 2, brr.Height * 2); // don't attempt to draw tiles that we don't need to if (tlsr.Width > 0 && tlsr.Height > 0) renderer.Draw(tld.Bitmap, tlr, tlsr); if (trsr.Width > 0 && trsr.Height > 0) renderer.Draw(trd.Bitmap, trr, trsr); if (blsr.Width > 0 && blsr.Height > 0) renderer.Draw(bld.Bitmap, blr, blsr); if (brsr.Width > 0 && brsr.Height > 0) renderer.Draw(brd.Bitmap, brr, brsr); continue; } else { // can't generate from children, so try generating one of the parents Key parent = key; Rectangle parentRect = sourceRect; TileData parentData = null; while (parent.Zoom >= 0 && parentData == null) { parentRect.Width /= 2; parentRect.Height /= 2; parentRect.X /= 2; parentRect.Y /= 2; if (parent.X % 2 == 1) parentRect.X += 128; if (parent.Y % 2 == 1) parentRect.Y += 128; parent.X /= 2; parent.Y /= 2; parent.Zoom--; TileCache.TryGetValue(parent, out parentData); } if (parentData != null && parentData.Bitmap != null) { // mark this tile as used recently parentData.LastUsed = tickCount; if (tileRect.Width > 0 && tileRect.Height > 0) renderer.Draw(parentData.Bitmap, tileRect, parentRect); continue; } else { // tile is being downloaded, and we have no parent or child images we can use to draw a temp // image. let's try to use a refresh bitmap. // tile is not available, and this is a transparent draw, // so dont draw at all if (HasAlpha) continue; if ((tile = RefreshBitmap) == null) { renderer.FillRectangle(BackColor, tileRect); continue; } } } } if (tile != null && tileRect.Width > 0 && tileRect.Height > 0) renderer.Draw(tile, tileRect, sourceRect); } } int pixelLevelZoom = myZoom + 8; int centerXReference = myCenterTile.X << 8; int centerYReference = myCenterTile.Y << 8; Geocode tlGeo = PointToGeocode(new Point(Math.Max(centerXReference + myCenterOffset.X - width / 2, 0), Math.Max(centerYReference + myCenterOffset.Y - height / 2, 0)), pixelLevelZoom); Geocode brGeo = PointToGeocode(new Point(Math.Min(centerXReference + myCenterOffset.X + width / 2, 1 << pixelLevelZoom), Math.Min(centerYReference + myCenterOffset.Y + height / 2, 1 << pixelLevelZoom)), pixelLevelZoom); int adjustX = midX - centerXReference; int adjustY = midY - centerYReference; foreach(Route route in myRoutes) { List<Point> points = new List<Point>(); Geocode lastOffscreenPoint = Geocode.Null; for (int i = 0; i < route.PolyLine.Length; i++) { Geocode geocode = route.PolyLine[i]; if (myLevelToZoom[route.Levels[i]] > myZoom) continue; // check if we're drawing off the screen if (!GeocodeBoxContains(tlGeo, brGeo, geocode)) { // if we're drawing from on screen to off screen, draw it, but note that // we are now off screen if (lastOffscreenPoint == Geocode.Null) points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY)); lastOffscreenPoint = geocode; continue; } // draw in from off the screen if necessary if (lastOffscreenPoint != Geocode.Null) points.Add(GeocodeToScreen(lastOffscreenPoint, pixelLevelZoom, adjustX, adjustY)); // note that we are now in screen space lastOffscreenPoint = Geocode.Null; points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY)); } if (points.Count > 1) renderer.DrawLines(route.LineWidth, Color.Cyan, points.ToArray()); } foreach (IMapOverlay overlay in Overlays) { DrawAtGeocode(tlGeo, brGeo, renderer, overlay.Geocode, pixelLevelZoom, adjustX + overlay.Offset.X, adjustY + overlay.Offset.Y, overlay.Drawable); } return unavailable; }
public void ConfigureRenderer(IMapRequestConfig requestConfig, IMapRenderer renderer) { ConfigureRenderer((WmsMapRequestConfig)requestConfig, (WmsRenderer)renderer); }
public void ConfigureRenderer(IMapRequestConfig requestConfig, IMapRenderer renderer) { ConfigureRenderer(requestConfig, (ImageMapRenderer)renderer); }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { if (key == Key.Root && !TileCache.ContainsKey(key)) TileCache.Add(Key.Root, new TileData(new StandardBitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("TiledMaps.VirtualEarth.msvemap.png")))); return base.GetTile(key, renderer, callback, state); }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { // make sure there's something to blend if (mySessions.Count == 0) return null; // see if we need to update this tile at all int currentBlend = 0; if (mySessionBlend.TryGetValue(key, out currentBlend) && currentBlend == myTotalBlend) return TileCache[key]; // see how many tiles we can blend int canBlend = 0; for (int i = 0; i < mySessions.Count; i++) { if (!mySessionEnabled[i]) continue; TileData data = mySessions[i].GetTile(key, renderer, callback, state); if (data != null && data.Bitmap != null) canBlend++; } // if there's nothing new to blend, don't if (canBlend == currentBlend) return null; mySessionBlend[key] = canBlend; // get the target bitmap ready if (RefreshBitmap == null) throw new InvalidOperationException("You must provide a RefreshBitmap"); StandardBitmap refreshBitmap = RefreshBitmap as StandardBitmap; int width = refreshBitmap.Width; int height = refreshBitmap.Height; StandardBitmap bitmap = new StandardBitmap(new Bitmap(width, height)); using (Graphics graphics = Graphics.FromImage(bitmap.Bitmap)) { refreshBitmap.Draw(graphics, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height)); } // draw the bitmaps using (Graphics graphics = Graphics.FromImage(bitmap.Bitmap)) { for (int i = 0; i < mySessions.Count; i++) { TiledMapSession session = mySessions[i]; if (!mySessionEnabled[i]) continue; TileData tile = mySessions[i].GetTile(key, renderer, callback, state); if (tile == null) continue; IGraphicsDrawable tileBitmap = tile.Bitmap as IGraphicsDrawable; tileBitmap.Draw(graphics, new Rectangle(0, 0, 256, 256), new Rectangle(0, 0, 256, 256)); if (ClearBlendedTiles && canBlend == myTotalBlend) { tileBitmap.Dispose(); mySessions[i].TileCache.Remove(key); } } } TileData ret; if (!TileCache.TryGetValue(key, out ret)) { ret = new TileData(); TileCache.Add(key, ret); } else if (ret.Bitmap != null) { ret.Bitmap.Dispose(); ret.Bitmap = null; } // TODO: optimize to do a lock/read load MemoryStream mem = new MemoryStream(); bitmap.Bitmap.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp); mem.Seek(0, SeekOrigin.Begin); ret.Bitmap = myRenderer.LoadBitmap(mem, false); return ret; }
public AsyncRenderWrapper(IMapRenderer renderer) { _actualRenderer = renderer; }
public EditorWindow() { InitializeComponent(); mapRenderer = new VectorMapRenderer(new Render.Configuration.RenderConfiguration()); RenderMap(); }
public void ConfigureRenderer(IMapRequestConfig requestConfig, IMapRenderer renderer) { ConfigureRenderer((BasicMapRequestConfig)requestConfig, (DefaultImageRenderer)renderer); }
private void SetMapRenderer(IMapRenderer renderer) { mapRenderer = renderer; RerenderMap(); }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { TileData tileData = null; // try to get the tile if (TileCache.TryGetValue(key, out tileData)) { if (tileData != InvalidTile) { return(tileData); } TileCache.Remove(key); } // check if it is in the file cache string tilePath = GetTilePathForKey(key); if (File.Exists(tilePath)) { FileInfo finfo = new FileInfo(tilePath); if (DateTime.Now - finfo.CreationTime > new TimeSpan(2, 0, 0, 0)) { // tile is old, expire it File.Delete(tilePath); } else { TileCache[key] = null; ThreadPool.QueueUserWorkItem((o) => { try { using (FileStream fstream = new FileStream(tilePath, FileMode.Open)) { IMapDrawable bitmap = renderer.GetBitmapFromStream(this, fstream); TileCache[key] = new TileData(bitmap); if (callback != null) { callback(state); } } } catch (Exception) { File.Delete(tilePath); } }); return(null); } } // check if its a bad key Uri uri = GetUriForKey(key); if (uri != null) { // mark tile as being downloaded TileCache[key] = null; GetTileData data = new GetTileData(); data.Renderer = renderer; data.Key = key; data.Callback = callback; data.State = state; data.Uri = uri; ThreadPool.QueueUserWorkItem(new WaitCallback(GetTile), data); //GetTile(data); } return(tileData); }
void DrawAtGeocode(Geocode tlGeo, Geocode brGeo, IMapRenderer renderer, Geocode geocode, int pixelLevelZoom, int adjustX, int adjustY, IMapDrawable drawable) { if (!GeocodeBoxContains(tlGeo, brGeo, geocode) || drawable == null) return; Point p = GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY); renderer.Draw(drawable, new Rectangle(p.X - drawable.Width / 2, p.Y - drawable.Height / 2, drawable.Width, drawable.Height), new Rectangle(0, 0, drawable.Width, drawable.Height)); }
public InventoryPanel(IRenderWindow renderWindow, IItemManager itemManager, IMapRenderer mapRenderer, ISessionManager sessionManager, Func <eItemContainerType, IItemContainer> createItemContainer, IGameState gameState, Func <eButtonType, IButton> createButton) { this.renderWindow = renderWindow; this.mapRenderer = mapRenderer; this.gameState = gameState; sessionManager.OnFocusOnPlayer += OnFocusOnPlayer; sessionManager.OnPlayerInfo += OnPlayerInfo; sessionManager.OnChangeEquipment += OnChangeEquipment; panelSprite = renderWindow.LoadSprite(ResourcePaths.InventoryCharacterPanel, Palettes.Units, FrameType.GetOffset(), true); closeButton = createButton(eButtonType.Close); closeButton.Location = panelSprite.Location + new Size(18, 384); closeButton.OnActivate = () => OnPanelClosed?.Invoke(this); secondaryLeftButton = createButton(eButtonType.SecondaryInvHand); secondaryLeftButton.Location = panelSprite.Location + new Size(15, 22); secondaryLeftButton.OnActivate = ToggleWeaponsSlot; secondaryRightButton = createButton(eButtonType.SecondaryInvHand); secondaryRightButton.Location = panelSprite.Location + new Size(246, 22); secondaryRightButton.OnActivate = ToggleWeaponsSlot; goldButton = createButton(eButtonType.GoldCoin); goldButton.Location = panelSprite.Location + new Size(84, 391); goldButton.OnActivate = OpenGoldDrop; headContainer = createItemContainer(eItemContainerType.Helm); headContainer.Location = panelSprite.Location + new Size(135, 5); headContainer.Slot = "head"; neckContainer = createItemContainer(eItemContainerType.Amulet); neckContainer.Location = panelSprite.Location + new Size(209, 34); neckContainer.Slot = "neck"; torsoContainer = createItemContainer(eItemContainerType.Armor); torsoContainer.Location = panelSprite.Location + new Size(135, 75); torsoContainer.Slot = "tors"; rightHandContainer = createItemContainer(eItemContainerType.Weapon); rightHandContainer.Location = panelSprite.Location + new Size(20, 47); rightHandContainer.Slot = "rarm"; leftHandContainer = createItemContainer(eItemContainerType.Weapon); leftHandContainer.Location = panelSprite.Location + new Size(253, 47); leftHandContainer.Slot = "larm"; secondaryLeftHandContainer = createItemContainer(eItemContainerType.Weapon); secondaryLeftHandContainer.Location = panelSprite.Location + new Size(24, 45); secondaryRightHandContainer = createItemContainer(eItemContainerType.Weapon); secondaryRightHandContainer.Location = panelSprite.Location + new Size(257, 45); beltContainer = createItemContainer(eItemContainerType.Belt); beltContainer.Location = panelSprite.Location + new Size(136, 178); beltContainer.Slot = "belt"; ringLeftContainer = createItemContainer(eItemContainerType.Ring); ringLeftContainer.Location = panelSprite.Location + new Size(95, 179); ringLeftContainer.Slot = "rrin"; ringRightContainer = createItemContainer(eItemContainerType.Ring); ringRightContainer.Location = panelSprite.Location + new Size(209, 179); ringRightContainer.Slot = "lrin"; gloveContainer = createItemContainer(eItemContainerType.Glove); gloveContainer.Location = panelSprite.Location + new Size(20, 179); gloveContainer.Slot = "glov"; bootsContainer = createItemContainer(eItemContainerType.Boots); bootsContainer.Location = panelSprite.Location + new Size(251, 178); bootsContainer.Slot = "feet"; }
public void RegisMapRenderer([NotNull] IMapRenderer mapRenderer) { }
public override TileData GetTile(TiledMapSession.Key key, IMapRenderer renderer, System.Threading.WaitCallback callback, object state) { // make sure there's something to blend if (mySessions.Count == 0) { return(null); } // see if we need to update this tile at all int currentBlend = 0; if (mySessionBlend.TryGetValue(key, out currentBlend) && currentBlend == myTotalBlend) { return(TileCache[key]); } // see how many tiles we can blend int canBlend = 0; for (int i = 0; i < mySessions.Count; i++) { if (!mySessionEnabled[i]) { continue; } TileData data = mySessions[i].GetTile(key, renderer, callback, state); if (data != null && data.Bitmap != null) { canBlend++; } } // if there's nothing new to blend, don't if (canBlend == currentBlend) { return(null); } mySessionBlend[key] = canBlend; // get the target bitmap ready if (RefreshBitmap == null) { throw new InvalidOperationException("You must provide a RefreshBitmap"); } StandardBitmap refreshBitmap = RefreshBitmap as StandardBitmap; int width = refreshBitmap.Width; int height = refreshBitmap.Height; StandardBitmap bitmap = new StandardBitmap(new Bitmap(width, height)); using (Graphics graphics = Graphics.FromImage(bitmap.Bitmap)) { refreshBitmap.Draw(graphics, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height)); } // draw the bitmaps using (Graphics graphics = Graphics.FromImage(bitmap.Bitmap)) { for (int i = 0; i < mySessions.Count; i++) { TiledMapSession session = mySessions[i]; if (!mySessionEnabled[i]) { continue; } TileData tile = mySessions[i].GetTile(key, renderer, callback, state); if (tile == null) { continue; } IGraphicsDrawable tileBitmap = tile.Bitmap as IGraphicsDrawable; tileBitmap.Draw(graphics, new Rectangle(0, 0, 256, 256), new Rectangle(0, 0, 256, 256)); if (ClearBlendedTiles && canBlend == myTotalBlend) { tileBitmap.Dispose(); mySessions[i].TileCache.Remove(key); } } } TileData ret; if (!TileCache.TryGetValue(key, out ret)) { ret = new TileData(); TileCache.Add(key, ret); } else if (ret.Bitmap != null) { ret.Bitmap.Dispose(); ret.Bitmap = null; } // TODO: optimize to do a lock/read load MemoryStream mem = new MemoryStream(); bitmap.Bitmap.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp); mem.Seek(0, SeekOrigin.Begin); ret.Bitmap = myRenderer.LoadBitmap(mem, false); return(ret); }
public int DrawMap(IMapRenderer renderer, int x, int y, int width, int height, WaitCallback callback, object state) { int unavailable = 0; // approximate the the top left tile (it may be off by 1), but the loop // below will kept it from being drawn int midX = x + width / 2 - myCenterOffset.X; int midY = y + height / 2 - myCenterOffset.Y; int xTiles = (midX - x) / 256 + 1; int yTiles = (midY - y) / 256 + 1; Key currentXKey = new Key(myCenterTile.X - xTiles, myCenterTile.Y - yTiles, myZoom); int xStart = midX - xTiles * 256; int yStart = midY - yTiles * 256; Rectangle rect = new Rectangle(x, y, width, height); int tickCount = Environment.TickCount; for (int currentX = xStart; currentX < x + width; currentX += 256, currentXKey.X++) { Key key = currentXKey; for (int currentY = yStart; currentY < y + height; currentY += 256, key.Y++) { IMapDrawable tile = null; // find the intersect region of the tile that we are drawing Rectangle tileRect = new Rectangle(currentX, currentY, 256, 256); tileRect.Intersect(rect); Rectangle sourceRect = new Rectangle(tileRect.X - currentX, tileRect.Y - currentY, tileRect.Width, tileRect.Height); // dont draw off the map tiles if (!key.IsValid) { // dont draw gray rect if we're drawing transparent if (!HasAlpha) { renderer.FillRectangle(BackColor, tileRect); } continue; } // first try to get the tile from the tileData TileData tileData = GetTile(key, renderer, callback, state); if (tileData != null) { tile = tileData.Bitmap; tileData.LastUsed = tickCount; } if (tile == null) { // tile not available, so try to generate a tile from child tiles unavailable++; Key childKey = new Key(key.X * 2, key.Y * 2, key.Zoom + 1); Key tl = childKey; Key tr = new Key(childKey.X + 1, childKey.Y, childKey.Zoom); Key br = new Key(childKey.X + 1, childKey.Y + 1, childKey.Zoom); Key bl = new Key(childKey.X, childKey.Y + 1, childKey.Zoom); TileData tld; TileData trd; TileData bld; TileData brd; // see if the children are available // we also need to null check, because they could be loading if (TileCache.TryGetValue(tl, out tld) && TileCache.TryGetValue(tr, out trd) && TileCache.TryGetValue(br, out brd) && TileCache.TryGetValue(bl, out bld) && tld != null && trd != null && bld != null & brd != null && tld.Bitmap != null && trd.Bitmap != null && bld.Bitmap != null && brd.Bitmap != null) { // children are available, so mark them as recently used tld.LastUsed = trd.LastUsed = bld.LastUsed = brd.LastUsed = tickCount; // calculate the destination rects of each child tile Rectangle tlr = new Rectangle(currentX, currentY, 128, 128); Rectangle trr = new Rectangle(currentX + 128, currentY, 128, 128); Rectangle blr = new Rectangle(currentX, currentY + 128, 128, 128); Rectangle brr = new Rectangle(currentX + 128, currentY + 128, 128, 128); tlr.Intersect(rect); trr.Intersect(rect); blr.Intersect(rect); brr.Intersect(rect); // calculate the source rect of each child tile Rectangle tlsr = new Rectangle(tlr.X - currentX, tlr.Y - currentY, tlr.Width * 2, tlr.Height * 2); Rectangle trsr = new Rectangle(trr.X - currentX - 128, trr.Y - currentY, trr.Width * 2, trr.Height * 2); Rectangle blsr = new Rectangle(blr.X - currentX, blr.Y - currentY - 128, blr.Width * 2, blr.Height * 2); Rectangle brsr = new Rectangle(brr.X - currentX - 128, brr.Y - currentY - 128, brr.Width * 2, brr.Height * 2); // don't attempt to draw tiles that we don't need to if (tlsr.Width > 0 && tlsr.Height > 0) { renderer.Draw(tld.Bitmap, tlr, tlsr); } if (trsr.Width > 0 && trsr.Height > 0) { renderer.Draw(trd.Bitmap, trr, trsr); } if (blsr.Width > 0 && blsr.Height > 0) { renderer.Draw(bld.Bitmap, blr, blsr); } if (brsr.Width > 0 && brsr.Height > 0) { renderer.Draw(brd.Bitmap, brr, brsr); } continue; } else { // can't generate from children, so try generating one of the parents Key parent = key; Rectangle parentRect = sourceRect; TileData parentData = null; while (parent.Zoom >= 0 && parentData == null) { parentRect.Width /= 2; parentRect.Height /= 2; parentRect.X /= 2; parentRect.Y /= 2; if (parent.X % 2 == 1) { parentRect.X += 128; } if (parent.Y % 2 == 1) { parentRect.Y += 128; } parent.X /= 2; parent.Y /= 2; parent.Zoom--; TileCache.TryGetValue(parent, out parentData); } if (parentData != null && parentData.Bitmap != null) { // mark this tile as used recently parentData.LastUsed = tickCount; if (tileRect.Width > 0 && tileRect.Height > 0) { renderer.Draw(parentData.Bitmap, tileRect, parentRect); } continue; } else { // tile is being downloaded, and we have no parent or child images we can use to draw a temp // image. let's try to use a refresh bitmap. // tile is not available, and this is a transparent draw, // so dont draw at all if (HasAlpha) { continue; } if ((tile = RefreshBitmap) == null) { renderer.FillRectangle(BackColor, tileRect); continue; } } } } if (tile != null && tileRect.Width > 0 && tileRect.Height > 0) { renderer.Draw(tile, tileRect, sourceRect); } } } int pixelLevelZoom = myZoom + 8; int centerXReference = myCenterTile.X << 8; int centerYReference = myCenterTile.Y << 8; Geocode tlGeo = PointToGeocode(new Point(Math.Max(centerXReference + myCenterOffset.X - width / 2, 0), Math.Max(centerYReference + myCenterOffset.Y - height / 2, 0)), pixelLevelZoom); Geocode brGeo = PointToGeocode(new Point(Math.Min(centerXReference + myCenterOffset.X + width / 2, 1 << pixelLevelZoom), Math.Min(centerYReference + myCenterOffset.Y + height / 2, 1 << pixelLevelZoom)), pixelLevelZoom); int adjustX = midX - centerXReference; int adjustY = midY - centerYReference; foreach (Route route in myRoutes) { List <Point> points = new List <Point>(); Geocode lastOffscreenPoint = Geocode.Null; for (int i = 0; i < route.PolyLine.Length; i++) { Geocode geocode = route.PolyLine[i]; if (myLevelToZoom[route.Levels[i]] > myZoom) { continue; } // check if we're drawing off the screen if (!GeocodeBoxContains(tlGeo, brGeo, geocode)) { // if we're drawing from on screen to off screen, draw it, but note that // we are now off screen if (lastOffscreenPoint == Geocode.Null) { points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY)); } lastOffscreenPoint = geocode; continue; } // draw in from off the screen if necessary if (lastOffscreenPoint != Geocode.Null) { points.Add(GeocodeToScreen(lastOffscreenPoint, pixelLevelZoom, adjustX, adjustY)); } // note that we are now in screen space lastOffscreenPoint = Geocode.Null; points.Add(GeocodeToScreen(geocode, pixelLevelZoom, adjustX, adjustY)); } if (points.Count > 1) { renderer.DrawLines(route.LineWidth, Color.Cyan, points.ToArray()); } } foreach (IMapOverlay overlay in Overlays) { DrawAtGeocode(tlGeo, brGeo, renderer, overlay.Geocode, pixelLevelZoom, adjustX + overlay.Offset.X, adjustY + overlay.Offset.Y, overlay.Drawable); } return(unavailable); }