public ModInfo() { try { NewGamePanel newGamePanel = UIView.library.Get <NewGamePanel>("NewGamePanel"); if (newGamePanel != null) { if (options != null) { options.Destroy(); } options = new Options(newGamePanel); SimulationManager.RegisterSimulationManager(new NewGamePlusSimManager()); pluginsChanged(); PluginManager.instance.eventPluginsChanged += pluginsChanged; PluginManager.instance.eventPluginsStateChanged += pluginsChanged; } } catch (Exception e) { Debug.LogException(e); } }
public LoginScreen() { InitializeComponent(); NewGamePanel.Enabled = false; NewGamePanel.Hide(); (NewGamePanel as Control).KeyDown += new KeyEventHandler(GamePanelKeyPress); //GamePanel.Enabled = false; //GamePanel.Hide(); this.DoubleBuffered = true; }
void Awake() { instance = this; startPanel = transform.Find("PanelStart").GetComponent <StartPanel>(); newGamePanel = transform.Find("PanelNewGame").GetComponent <NewGamePanel>(); joinGamePanel = transform.Find("PanelJoinGame").GetComponent <JoinGamePanel>(); settingPanel = transform.Find("PanelSetting").GetComponent <SettingPanel>(); exitPanel = transform.Find("PanelExit").GetComponent <ExitPanel>(); messagePanel = transform.Find("PanelMessage").GetComponent <MessagePanel>(); playerInfoPanel = transform.Find("PanelPlayerInfo").GetComponent <PlayerInfoPanel>(); teamPanel = transform.Find("PanelTeam").GetComponent <TeamPanel>(); shopPanel = transform.Find("PanelShop"); curHangingText = transform.Find("CurHanging").GetComponent <Text>(); curInGamingText = transform.Find("CurInGaming").GetComponent <Text>(); }
public Options(NewGamePanel newGamePanel) { this.newGamePanel = newGamePanel; this.ngpPanel = newGamePanel.component.AddUIComponent <UIPanel>(); UIComponent newgameCaption = newGamePanel.component.Find("Caption"); UIComponent closeButton = newGamePanel.component.Find("Close"); // uncomment if you want it visible // ngpPanel.backgroundSprite = ""; // ngpPanel.color = new Color32(255,255,255,255); ngpPanel.width = newGamePanel.component.width; ngpPanel.height = newgameCaption.height * 0.9f; ngpPanel.autoLayout = true; ngpPanel.autoLayoutDirection = LayoutDirection.Horizontal; ngpPanel.autoLayoutStart = LayoutStart.TopLeft; ngpPanel.autoLayoutPadding = new RectOffset(4, 4, 2, 2); if (Base.Config.StartMoney < 0 || Base.Config.StartMoney > maxMoney) { Base.Config.StartMoney = 70000; } CreateButton(ngpPanel, "-", DecreaseMoney); label = CreateLabel(ngpPanel, FormatMoney(maxMoney)); label.text = FormatMoney(Base.Config.StartMoney); CreateButton(ngpPanel, "+", IncreaseMoney); CreateCheckbox(SPRITE_HIGHWAY, ngpPanel, Base.Config.AllRoads, (e) => Base.Config.AllRoads = e, "all roads enabled from the start"); CreateCheckbox(SPRITE_AREA, ngpPanel, Base.Config.AllAreas, (e) => Base.Config.AllAreas = e, "all areas purchaseable from the start"); CreateCheckbox(SPRITE_BUS, ngpPanel, Base.Config.Buses, (e) => Base.Config.Buses = e, "busses enabled from the start"); CreateCheckbox(SPRITE_METRO, ngpPanel, Base.Config.Subways, (e) => Base.Config.Subways = e, "metros enabled from the start"); CreateCheckbox(SPRITE_TRAIN, ngpPanel, Base.Config.Trains, (e) => Base.Config.Trains = e, "trains enabled from the start"); CreateCheckbox(SPRITE_SHIP, ngpPanel, Base.Config.Ships, (e) => Base.Config.Ships = e, "ships enabled from the start"); CreateCheckbox(SPRITE_PLANE, ngpPanel, Base.Config.Airplanes, (e) => Base.Config.Airplanes = e, "airports enabled from the start"); ngpPanel.pivot = UIPivotPoint.TopRight; ngpPanel.transformPosition = new Vector3(closeButton.GetBounds().max.x, closeButton.GetBounds().min.y, 0); ngpPanel.relativePosition += new Vector3(0, 3, 0); // I don't know why you can resize the panel after it has been placed, but it works and resizing it seems to be necessary ngpPanel.width = getChildrenWidth(ngpPanel); }
/// <summary> /// Handles enter key press when name is entered. Causes the game to start. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Key_down(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { World = new World(); if (!connected) { socket = Network.Connect_to_Server(CallbackName, ServerTextBox.Text); connected = true; } NewGamePanel.Show(); NewGamePanel.Enabled = true; NewGamePanel.Focus(); PlayerNameTextBox.Enabled = false; //GamePanel.Show(); //GamePanel.Enabled = true; } }
/// <summary> /// Paints the world onto the game panel. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewGamePanel_Paint(object sender, PaintEventArgs e) { //Console.Out.WriteLine("Paint"); Dictionary <int, Cube> WorldCubes = World.getCubes(); if (PlayerCube == null) { return; } //try //{ lock (World) { // Coordinates of player cube, used to draw player centered view. double PlayerX = PlayerCube.XCoord; double PlayerY = PlayerCube.YCoord; double PlayerSize = PlayerCube.WidthHeight; // "Scale" of cubes double ViewScalar = 1; foreach (int key in WorldCubes.Keys) { Color color = Color.FromArgb((int)WorldCubes[key].RGBColor); brush = new System.Drawing.SolidBrush(color); // Values to convert values for player-centered screen view. double CubeXCoord = WorldCubes[key].XCoord - PlayerX + (((750 - (PlayerSize * ViewScalar)) / 2)) - (PlayerSize / 2); double CubeYCoord = WorldCubes[key].YCoord - PlayerY + (((750 - (PlayerSize * ViewScalar)) / 2)) - (PlayerSize / 2); double CubeSize = WorldCubes[key].WidthHeight * ViewScalar; Rectangle CubeTangle = new Rectangle(0, 0, 0, 0); bool IsDrawn = false; // If cube will be displayed, draw it. //if (!(CubeXCoord + CubeSize < 0 && CubeYCoord + CubeSize < 0) && !(CubeXCoord > 750 && CubeYCoord > 750)) //{ if (CubeXCoord < 0) { } CubeTangle = new Rectangle((int)CubeXCoord, (int)CubeYCoord, (int)CubeSize, (int)CubeSize); IsDrawn = true; e.Graphics.FillRectangle(brush, CubeTangle); //} //CubeTangle = new Rectangle((int)WorldCubes[key].XCoord, (int)WorldCubes[key].YCoord, WorldCubes[key].WidthHeight, WorldCubes[key].WidthHeight); //e.Graphics.FillRectangle(brush, CubeTangle); //Console.Out.WriteLine("x: " + cube.XCoord + " " + "y: " + cube.YCoord); // Name of player cube. if ((!(WorldCubes[key].Food) && WorldCubes[key].CubeMass > 0) && IsDrawn) { color = Color.FromArgb((int)WorldCubes[key].RGBColor + 50000); //int RectX = (int)WorldCubes[key].XCoord + ((int)WorldCubes[key].WidthHeight / 2) - ((((int)WorldCubes[key].XCoord + ((int)WorldCubes[key].WidthHeight) / 2)) / 2); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(WorldCubes[key].CubeName, new Font("Arial", 12), new System.Drawing.SolidBrush(color), CubeTangle, stringFormat); } if (WorldCubes[key].UID == PlayerCube.UID) { PlayerCube = WorldCubes[key]; MassLabel.Text = PlayerCube.CubeMass.ToString(); } } } //} //catch (Exception ex) //{ // Console.Out.WriteLine("DAMN"); //} if (NameSent) { Network.Send(socket, "(move, " + x_dest + ", " + y_dest + ")\n"); } NewGamePanel.Invalidate(); }
/// <summary> /// Method called each time new data is recieved from socket beyond inital player info. Reads info and adds to world. /// </summary> /// <param name="state"></param> private void RepaintData(State state) { string incomingChanges = System.Text.Encoding.UTF8.GetString(state.Bytes); state.Bytes = new byte[1024]; DataString = incomingChanges.Substring(0, incomingChanges.LastIndexOf('\n')); if (!(DataString == "") && (!(DataString.First() == '{'))) { string StartOfDataCutoff; try { StartOfDataCutoff = DataString.Substring(0, DataString.IndexOf('\n')); DataString = DataString.Substring(DataString.IndexOf('\n') + 1); } catch (ArgumentOutOfRangeException) { StartOfDataCutoff = DataString; DataString = ""; } string MergedJson = EndOfDataCutoff + StartOfDataCutoff; lock (World) { World.addCube(JsonConvert.DeserializeObject <Cube>(MergedJson)); } } try { EndOfDataCutoff = incomingChanges.Substring(incomingChanges.LastIndexOf('\n') + 1); } catch (NullReferenceException) { EndOfDataCutoff = ""; } // Game Over if (PlayerCube.CubeMass == 0) { MessageBox.Show(null, "GAME OVER", "GAMEOVER"); } // Name of player cube. if (!(DataString == "")) { char[] Splitta = { '\n' }; string[] CubeStrings = DataString.Split(Splitta); lock (World) { foreach (string cubeJson in CubeStrings) { Cube NewCube = JsonConvert.DeserializeObject <Cube>(cubeJson); World.addCube(NewCube); } } } PreviousIncomingChanges = incomingChanges; NewGamePanel.Invalidate(); Network.i_want_more_data(state); }