public override void doAction(TextureManager TM, HudManager HM) { //remove old submenu int i = 0; int count = HM.hudGraphicsCount(); //can't do this in a for loop since we remove elements from the list... while (i < count) { if (HM.getGraphicAt(i).getOrientation() == ORIENTATION.NONE) { HM.getGraphics().RemoveAt(i); count--; } else { i++; } } //now we swap the clicked HudGraphic's action to "createSubMenu" Action A = new createSubMenu(bias); A.setIndex(index); HM.getGraphicAt(index).setAction(A); }
//interpret mouse click public Action interpretClick(Globals G, HudManager HM) { Action A = null; Point P = new Point(G.mouseX, G.mouseY); Point size = new Point(1, 1); Rectangle mousePos = new Rectangle(P, size); int i = 0; //first and foremost, did we click on a hud element??? for (i = 0; i < HM.hudGraphicsCount(); i++) { if (HM.getGraphicAt(i).getClickBox().Intersects(mousePos)) { A = HM.getGraphicAt(i).getAction(); A.setIndex(i); } } return(A); }
/// <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) { int WIDTH = (G.graphicsWidth / G.tileSize); int HEIGHT = (G.graphicsHeight / G.tileSize); int i, j = 0; int camX = 0; int camY = 0; GraphicsDevice.Clear(Color.TransparentBlack); spriteBatch.Begin(); //draw TILES camX = M.getCamX(); camY = M.getCamY(); for (i = 0; i < HEIGHT; i++) { for (j = 0; j < WIDTH; j++) { tile T = M.getTileAt(camX + j, camY + i); Vector2 pos = new Vector2(j * G.tileSize, i * G.tileSize); spriteBatch.Draw(T.getTexture(), pos, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1f); } } //draw all HUD elements for (i = 0; i < HM.hudGraphicsCount(); i++) { //ignore hidden stuff if (HM.getGraphicAt(i).getState() == VISIBILITY.HIDDEN) { continue; } HudGraphic HG = HM.getGraphicAt(i); spriteBatch.Draw(HG.getTexture(), HG.getPosition(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1f); } //draw all hud text for (i = 0; i < HM.hudTextCount(); i++) { //ignore hidden stuff if (HM.getTextAt(i).getState() == VISIBILITY.HIDDEN) { continue; } HudText HT = HM.getTextAt(i); spriteBatch.DrawString(HT.getFont(), HT.getText(), HT.getPosition(), Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 0); } //draw crosshair spriteBatch.Draw(TM.crosshair, new Vector2(G.mouseX, G.mouseY), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1f); //draw bottom bar //spriteBatch.Draw(TM.UI[0], new Vector2(0, 700), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1f); //draw current position //string position = "pos:(" + camX + "," + camY + ")"; //spriteBatch.DrawString(defaultFont, position, new Vector2(0, 702), Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 0); //draw current time //string date = "day:" + DT.getDay(); //spriteBatch.DrawString(defaultFont, date, new Vector2(150, 702), Color.White, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 0); //draw resources base.Draw(gameTime); spriteBatch.End(); return; }