public void SetMaxDistance(double kilometers) { Func <DataList, bool> filterFunc = (data) => { object coords = data.Get("coordinates"); if (coords != null) { object lat = ((DataList)coords).Get(0); object lon = ((DataList)coords).Get(1); try { UserData user = Program.UserDataManager.GetData(); return(MathSupplement.Distance(user.Latitude, user.Longitude, (double)lat, (double)lon) <= kilometers * 1000.0); } catch (InvalidCastException) { return(false); } } else { return(false); } }; // Add filter if (!filter.AddFilter("distance_filter", filterFunc)) { filter.CreateAndAddFilter("distance_filter", true, filterFunc); } }
// Update is called once per frame void Update() { // determine the furthest finger and see how 'far' we've pushed things. if (FingertipsInCollisionBounds.Count > 0) { furthestPushPoint = ButtonFaceDistance; for (int i = 0; i < FingertipsInCollisionBounds.Count; i++) { float fingerDot = Vector3.Dot(FingertipsInCollisionBounds[i].transform.forward, transform.forward); // 1 is orthogonal, 0 is perpendicular, -1 is inverse orthogonal. -1 is what we want. fingerDots[i] = fingerDot; if (fingerDot > -0.7f) { continue; // finger is probably facing down. Ignore it. } Vector3 fingertipPosition = HandModel.fingers[(int)HandProperties.FingerTypeFromFingerFilter(FingerTipFilters[i])].GetTipPosition(); fingertipPosition = transform.InverseTransformPoint(fingertipPosition); if (furthestPushPoint > fingertipPosition.z) { furthestPushPoint = fingertipPosition.z; } } if (!WaitingForReactivation) { CurrentThrowValue = Mathf.InverseLerp(ButtonThrowDistance, ButtonFaceDistance, furthestPushPoint); //ThrowSource.volume = Mathf.Lerp(ThrowSource.volume, 1f, Time.deltaTime * 2); ThrowSource.volume = Mathf.Lerp(0f, 1f, MathSupplement.UnitReciprocal(CurrentThrowValue)); ThrowSource.pitch = Mathf.Lerp(1f, 1.84f, MathSupplement.UnitReciprocal(CurrentThrowValue)); if (furthestPushPoint < ButtonThrowDistance) { Activate(); } } else { if (furthestPushPoint >= ButtonThrowDistance) { WaitingForReactivation = false; if (EnableDebugLogging) { Debug.Log("Re-activation allowed."); } } } } else { ThrowSource.volume = 0; ThrowSource.pitch = 1; } }
// Update is called once per frame void Update() { base.Update(); if (TweenerState == TweenState.Play || RunWhileNotPlay) { if (Unclamped) { transform.localScale = MathSupplement.UnclampedLerp(StartScale, GoalScale, TValue); } else { transform.localScale = Vector3.Lerp(StartScale, GoalScale, TValue); } } }
IEnumerator ShowWindowCoroutine(Transform target) { showCoroutineStarted = true; float timer = 0; float tValue = 0; while (timer < windowTweenTime) { timer += Time.deltaTime; tValue = Mathf.InverseLerp(0, windowTweenTime, timer); target.transform.localScale = MathSupplement.Exerp(Vector3.zero, initialScale, tValue); yield return(null); } target.transform.localScale = initialScale; showCoroutineFinished = false; yield break; }
IEnumerator HideWindowCoroutine(Transform target) { Debug.Log("Hiding :" + target.name); hideCoroutineStarted = true; float timer = 0; float tValue = 0; while (timer < windowTweenTime) { timer += Time.deltaTime; tValue = Mathf.InverseLerp(0, windowTweenTime, timer); target.transform.localScale = MathSupplement.Exerp(initialScale, Vector3.zero, tValue); yield return(null); } target.transform.localScale = Vector3.zero; hideCoroutineFinished = true; yield break; }
void SetVertices() { float angleIncrement = 360 / EdgeLoopVertCount; float iterator = 0; for (int index = frontLoop.VertexBaseID; index < (frontLoop.VertexBaseID + frontLoop.VertCount); index++) { float angle = angleIncrement * iterator; Vector3 vertex = Vector3.up * radius; vertex = Quaternion.AngleAxis(angle, Vector3.forward) * vertex; vertices[index] = vertex; iterator++; } iterator = 0; for (int index = backLoop.VertexBaseID; index < (backLoop.VertexBaseID + frontLoop.VertCount); index++) { float angle = angleIncrement * iterator; Vector3 vertex = Vector3.up * radius; vertex = Quaternion.AngleAxis(angle, Vector3.forward) * vertex; vertex += (Vector3.forward * extrusionDepth); vertices[index] = vertex; iterator++; } // do our face bevel verts float extraExtrudeDepth = extrusionDepth * bevelExtrusionDepth; float totalExtrudeDepth = extraExtrudeDepth; float innerRadius = radius * bevelRadius; for (int i = 0; i < bevelSliceCount; i++) { float depthTValue = ((float)i + 1) / (float)bevelSliceCount; // precision loss is happening here. float tValue = (float)i / (float)bevelSliceCount; int startIndex = faceBevelLoops[i].VertexBaseID; int endIndex = startIndex + faceBevelLoops[i].VertCount; float sliceRadius = MathSupplement.Sinerp(innerRadius, radius, 1 - depthTValue); float sliceDepth = (i == bevelSliceCount - 1) ? Mathf.Lerp(extrusionDepth, totalExtrudeDepth, ((1 - tValue) + (1 - depthTValue)) * 0.5f) : Mathf.Lerp(extrusionDepth, totalExtrudeDepth, 1 - depthTValue); iterator = 0; for (int index = startIndex; index < endIndex; index++) { float angle = angleIncrement * iterator; Vector3 vertex = Vector3.up * sliceRadius; vertex = Quaternion.AngleAxis(angle, Vector3.forward) * vertex; vertex -= (Vector3.forward * sliceDepth); vertices[index] = vertex; iterator++; } } }
public UiEventDisplayPanel(int eventId, IPanel caller) { // Get full event data from database List <EventFull> events = Program.Client.SelectEventsFull(eventId); try { @event = events[0]; } catch (IndexOutOfRangeException) { Console.WriteLine($"ERROR: Event with id {eventId} not found"); throw; } UserAccount acc = Program.UserDataManager.UserAccount; this.caller = caller; InitializeComponent(); // Set return button image returnButton.BackgroundImage = Properties.Resources.BackButtonGreen; // Enforce permissions if (!acc.Can((uint)Permissions.CREATE_REPORTS)) { reportButton.Visible = false; } if (acc.Can((uint)Permissions.SET_EVENT_VISIBILITY)) { setVisibilityButton.Visible = true; if ([email protected]) { setVisibilityButton.BackColor = Color.FromArgb(109, 168, 135); setVisibilityButton.Text = "Make visible"; } else { setVisibilityButton.BackColor = Color.Tomato; setVisibilityButton.Text = "Make invisible"; } } if (!acc.Can((uint)Permissions.SEND_CHAT_MESSAGES)) { if (acc.Id == -1) { chatMessageTextBox.PlaceholderText = "Log in to comment"; chatMessageTextBox.Enabled = false; } else { chatMessageTextBox.PlaceholderText = "You don't have the permission to comment"; chatMessageTextBox.Enabled = false; } } // Title eventName.Text = @event.Name; // Sports foreach (var sport in @event.Sports) { Label sportLabel = new Label(); sportLabel.AutoSize = true; sportLabel.Text = sport; sportLabel.BackColor = Color.FromArgb(230, 230, 230); sportLabel.Font = new Font("Arial", 12, FontStyle.Bold); //sportDisplayBar.Controls.Add(sportLabel); } // Distance UserData user = Program.UserDataManager.GetData(); double distance = MathSupplement.Distance(@event.Latitude, @event.Longitude, user.Latitude, user.Longitude); if (distance < 1000.0) { distanceLabel.Text = $"{distance:0}m"; } else { distanceLabel.Text = $"{distance / 1000.0:0.0}km"; } // Distance and address separator Size distanceLabelSize = Helper.CalculateLabelSize(distanceLabel, 100); separatorPanel1.Location = new Point(distanceLabel.Location.X + distanceLabelSize.Width, separatorPanel1.Location.Y); // Address addressLabel.Location = new Point(distanceLabel.Location.X + distanceLabelSize.Width + 10, addressLabel.Location.Y); addressLabel.Text = @event.Address.ToStringNormal(); // Show map button Size addressLabelSize = Helper.CalculateLabelSize(addressLabel, 500); showMapsButton.Location = new Point(addressLabel.Location.X + addressLabelSize.Width + 5, showMapsButton.Location.Y); showMapsButton.BackgroundImage = Properties.Resources.MapsButton; // Load images List <string> imageLinks = @event.Images; int counter = 0; foreach (var image in @event.Images) { int IMAGE_WIDTH = 180; int IMAGE_HEIGHT = 180; int MARGINS = 10; PictureBox picture = new PictureBox(); picture.Size = new Size(IMAGE_WIDTH, IMAGE_HEIGHT); picture.Location = new Point((IMAGE_WIDTH + MARGINS) * counter, 0); picture.BorderStyle = BorderStyle.None; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { try { using (WebClient client = new WebClient()) { Stream stream = client.OpenRead(image); Bitmap bitmap = new Bitmap(stream); picture.Image = Helper.ScaleBitmap(bitmap, IMAGE_WIDTH, IMAGE_HEIGHT, 1.0f); stream.Flush(); stream.Close(); } } catch { } }; worker.RunWorkerAsync(); picturePanel.Controls.Add(picture); counter++; } picturePanel.VerticalScroll.Maximum = 0; picturePanel.AutoScroll = false; picturePanel.HorizontalScroll.Visible = false; picturePanel.AutoScroll = true; // Description descriptionLabel.Text = @event.Description; Size descriptionLabelSize = Helper.CalculateLabelSize(descriptionLabel, descriptionLabel.MaximumSize.Width); // Description and comment separator separatorPanel4.Location = new Point(separatorPanel4.Location.X, descriptionLabel.Location.Y + descriptionLabelSize.Height + 28); // Show reports List <Report> reports = Program.Client.SelectReports(eventId); int height = 0; if (reports.Count > 0) { reportsPanel.Visible = true; reportsPanel.Location = new Point(reportsPanel.Location.X, separatorPanel4.Location.Y + 10); reportsPanel.BackColor = Color.FromArgb(255, 200, 200); reportsPanel.HorizontalScroll.Maximum = 0; reportsPanel.AutoScroll = false; reportsPanel.VerticalScroll.Visible = false; reportsPanel.AutoScroll = true; height = 20; foreach (var report in reports) { Label reportType = new Label(); reportType.Text = report.Type; reportType.Font = new Font("Arial", 12, FontStyle.Bold); reportType.ForeColor = Color.FromArgb(64, 64, 64); reportType.Location = new Point(0, 0); reportType.AutoSize = false; reportType.Size = new Size(940, 26); reportType.TextAlign = ContentAlignment.MiddleLeft; Label reportComment = new Label(); reportComment.Text = report.Comment; reportComment.Font = new Font("Arial", 12); reportComment.ForeColor = Color.FromArgb(64, 64, 64); reportComment.Location = new Point(0, 26); reportComment.AutoSize = false; Size reportSize = Helper.CalculateLabelSize(reportComment, 940); reportComment.Size = new Size(940, reportSize.Height); reportComment.TextAlign = ContentAlignment.MiddleLeft; Panel reportPanel = new Panel(); reportPanel.Size = new Size(940, 26 + reportComment.Size.Height); reportPanel.Location = new Point(20, height); height += reportPanel.Size.Height + 20; reportPanel.Controls.Add(reportType); reportPanel.Controls.Add(reportComment); reportsPanel.Controls.Add(reportPanel); } if (height > 150) { height = 150; } reportsPanel.Size = new Size(reportsPanel.Size.Width, height); } // Comments panel commentsPanel.Location = new Point(commentsPanel.Location.X, separatorPanel4.Location.Y + 10 + height + 10 * (height > 0 ? 1 : 0)); // New comment chatMessageTextBox.Location = new Point(0, 0); // Submit new comment sendMessageButton.Location = new Point(sendMessageButton.Location.X, chatMessageTextBox.Location.Y + chatMessageTextBox.Size.Height + 6); // Chat panel chatPanel.Location = new Point(chatPanel.Location.X, sendMessageButton.Location.Y + sendMessageButton.Size.Height + 6); // Load comments List <Backend.Message> messages = Program.Client.SelectEventComments(@event.Id); messages.Reverse(); /* * messages.Add(new Backend.Message() * { * Sender = 0, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi" + * "lietuva hujon eina o algos tai irgi po jevrejo nebekyla, o vat maisto kainos tai ojojoj" + * "kaip i virsu skuodzia ir va kaip man uz minimuma pragyvent blyat kai reika nauja telef" + * "ona pirk kiekviena meta nu blet negerai cia", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 0, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 1, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 2, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 3, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 0, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); * messages.Add(new Backend.Message() * { * Sender = 0, * Content = "Gražulis blet sake kad ne gejus tai kuo ,man dabar tiket nx pasaulis ritasi", * SendTime = DateTime.Now * }); */ height = 0; if (messages.Count > 0) { chatPanel.Controls.Clear(); height = 20; foreach (var msg in messages) { string username = Program.Client.SelectAccountUsername(msg.Sender); Label senderInfoLabel = new Label(); senderInfoLabel.Text = $"By {username} at {msg.SendTime:yyyy-MM-dd HH:mm}"; senderInfoLabel.Font = new Font("Arial", 10, FontStyle.Italic); senderInfoLabel.ForeColor = Color.Gray; senderInfoLabel.Location = new Point(0, 0); senderInfoLabel.AutoSize = false; senderInfoLabel.Size = new Size(920, 20); senderInfoLabel.TextAlign = ContentAlignment.MiddleLeft; Label commentLabel = new Label(); commentLabel.Text = msg.Content; commentLabel.Font = new Font("Arial", 12); commentLabel.ForeColor = Color.FromArgb(64, 64, 64); commentLabel.BackColor = Color.White; commentLabel.Location = new Point(0, 20); commentLabel.Padding = new Padding(10); commentLabel.AutoSize = false; Size reportSize = Helper.CalculateLabelSize(commentLabel, 920); commentLabel.Size = new Size(920, reportSize.Height + 20); commentLabel.TextAlign = ContentAlignment.MiddleLeft; Panel commentPanel = new Panel(); commentPanel.Size = new Size(920, 20 + commentLabel.Size.Height); commentPanel.Location = new Point(20, height); height += commentPanel.Size.Height + 20; commentPanel.Controls.Add(senderInfoLabel); commentPanel.Controls.Add(commentLabel); chatPanel.Controls.Add(commentPanel); } chatPanel.Size = new Size(chatPanel.Size.Width, height); } commentsPanel.Size = new Size(commentsPanel.Size.Width, chatPanel.Location.Y + chatPanel.Size.Height); mainPanel.Size = new Size(1000, commentsPanel.Location.Y + commentsPanel.Size.Height + 20); // Chat chatMessageTextBox.KeyPress += new KeyPressEventHandler(Key_Press); // Start chat //chatManager = new ChatManager(); //chatManager.Connect(@event.Id, chatPanel); // Links //List<string> links = @event.Links; //for (int i = 0; i < links.Count; i++) //{ // string[] linkSplit = links[i].Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); // if (linkSplit.Length != 2) continue; // LinkLabel linkText = new LinkLabel(); // linkText.Text = linkSplit[1]; // linkText.LinkClicked += (sender, e) => // { // Process.Start(new ProcessStartInfo("cmd", $"/c start {linkSplit[0]}")); // }; // linkText.Location = new Point(426, 370 + (i * 20)); // Controls.Add(linkText); //} }
private void LoadMainEvents(EventOptions options) { CurrentEventsTable.Controls.Clear(); // Get events List <EventBrief> events = Program.DataProvider.GetEventsBrief(options); List <int> scores = new List <int>(); List <double> distances = new List <double>(); // Calculate distances UserData user = Program.UserDataManager.GetData(); bool isAddressAdded = !(user.Address == "" || user.Address == null || (user.Latitude == 0 && user.Longitude == 0)); foreach (var evBrief in events) { distances.Add(MathSupplement.Distance(user.Latitude, user.Longitude, evBrief.Latitude, evBrief.Longitude)); } if (options.Keywords.Count > 0) { // Calculate scores KeywordFinder kFinder = new KeywordFinder(); foreach (var evBrief in events) { DataList @event = evBrief.ToDataList(); scores.Add(kFinder.Find(options.Keywords.ToArray(), @event)); } // Sort by score EventBrief[] eventArray = events.ToArray(); int[] scoreArray = scores.ToArray(); Array.Sort(scoreArray, eventArray); events = eventArray.ToList(); scores = scoreArray.ToList(); events.Reverse(); scores.Reverse(); } else { // Sort by distance EventBrief[] eventArray = events.ToArray(); double[] distanceArray = distances.ToArray(); Array.Sort(distanceArray, eventArray); events = eventArray.ToList(); distances = distanceArray.ToList(); } // Add all of them to a list int col = 0; int count = 0; foreach (var eBrief in events) { // Skip events with 0 score if (scores.Count > 0) { if (scores[count] == 0) { count++; continue; } } // Main container Panel eventPanel = new Panel(); eventPanel.AutoSize = false; eventPanel.Size = new Size(240, 238); eventPanel.Margin = new Padding(43, 10, 43, 10); eventPanel.BorderStyle = BorderStyle.Fixed3D; eventPanel.Click += (sender, e) => { try { new UiEventDisplay(eBrief.Id, this).Show(); } catch { } }; // Thumbnail PictureBox thumbnail = new PictureBox(); thumbnail.Size = new Size(240, 180); thumbnail.Location = new Point(0, 0); thumbnail.Click += (sender, e) => { try { new UiEventDisplay(eBrief.Id, this).Show(); } catch { } }; try { using (WebClient client = new WebClient()) { Stream stream = client.OpenRead(eBrief.Images[0]); Bitmap bitmap = new Bitmap(stream); Bitmap bitmapScaled = new Bitmap(bitmap, new Size(240, 180)); thumbnail.Image = bitmapScaled; stream.Flush(); stream.Close(); } } catch { } // Name label Label eventName = new Label(); eventName.Text = eBrief.Name; eventName.AutoSize = true; eventName.Location = new Point(0, 180); eventName.MinimumSize = new Size(240, 30); eventName.Font = new Font("Arial Rounded", 12, FontStyle.Bold); eventName.BackColor = Color.FromArgb(240, 240, 240); eventName.TextAlign = ContentAlignment.MiddleLeft; // Sport label Label eventSports = new Label(); eventSports.Text = ""; eventSports.Font = new Font("Arial", 11); foreach (var sport in eBrief.Sports) { eventSports.Text += $"{sport} "; } eventSports.AutoSize = false; eventSports.Location = new Point(0, 210); eventSports.Size = new Size(180, 25); eventSports.BackColor = Color.FromArgb(230, 230, 230); eventSports.TextAlign = ContentAlignment.MiddleLeft; // Distance label Label eventDistance = new Label(); eventDistance.Text = ""; eventDistance.Font = new Font("Arial", 11, FontStyle.Bold); eventDistance.Text += $"{distances[count] / 1000.0:0.0}km"; eventDistance.AutoSize = false; eventDistance.Location = new Point(180, 210); eventDistance.Size = new Size(60, 25); eventDistance.BackColor = Color.FromArgb(230, 230, 230); eventDistance.TextAlign = ContentAlignment.MiddleCenter; if (!isAddressAdded) { eventDistance.Text = ""; } // Add everything eventPanel.Controls.Add(thumbnail); eventPanel.Controls.Add(eventName); eventPanel.Controls.Add(eventSports); eventPanel.Controls.Add(eventDistance); CurrentEventsTable.Controls.Add(eventPanel, col, count / CurrentEventsTable.ColumnCount); col = (++col) % CurrentEventsTable.ColumnCount; count++; // Redraw Invalidate(); } CurrentEventsTable.RowCount = (events.Count + 1) / CurrentEventsTable.ColumnCount; }
public UiEventDisplay(int eventId, Form caller) { this.caller = caller; InitializeComponent(); // Get full event data from database List <EventFull> events = Program.Client.SelectEventsFull(eventId); try { @event = events[0]; } catch (IndexOutOfRangeException) { Console.WriteLine($"ERROR: Event with id {eventId} not found"); throw; } // Title eventName.Text = @event.Name; // Sports foreach (var sport in @event.Sports) { Label sportLabel = new Label(); sportLabel.AutoSize = true; sportLabel.Text = sport; sportLabel.BackColor = Color.FromArgb(230, 230, 230); sportLabel.Font = new Font("Arial Rounded", 12, FontStyle.Bold); sportDisplayBar.Controls.Add(sportLabel); } // Address addressLabel.Text = @event.Address.ToStringNormal(); // Distance UserData user = Program.UserDataManager.GetData(); double distance = MathSupplement.Distance(@event.Latitude, @event.Longitude, user.Latitude, user.Longitude); if (distance < 1000.0) { distanceLabel.Text = $"{distance:0}m"; } else { distanceLabel.Text = $"{distance / 1000.0:0.0}km"; } // Description descriptionLabel.Text = @event.Description; // Links List <string> links = @event.Links; for (int i = 0; i < links.Count; i++) { string[] linkSplit = links[i].Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); if (linkSplit.Length != 2) { continue; } LinkLabel linkText = new LinkLabel(); linkText.Text = linkSplit[1]; linkText.LinkClicked += (sender, e) => { Process.Start(new ProcessStartInfo("cmd", $"/c start {linkSplit[0]}")); }; linkText.Location = new Point(426, 370 + (i * 20)); Controls.Add(linkText); } // Load images List <string> imageLinks = @event.Images; for (int i = 0; i < imageLinks.Count; i++) { PictureBox picture = new PictureBox(); picture.Size = new Size(240, 180); picture.Location = new Point(0, 200 * i); picture.BorderStyle = BorderStyle.Fixed3D; try { using (WebClient client = new WebClient()) { Stream stream = client.OpenRead(imageLinks[i]); Bitmap bitmap = new Bitmap(stream); Bitmap bitmapScaled = new Bitmap(bitmap, new Size(240, 180)); picture.Image = bitmapScaled; stream.Flush(); stream.Close(); } } catch { } picturePanel.Controls.Add(picture); } picturePanel.HorizontalScroll.Maximum = 0; picturePanel.AutoScroll = false; picturePanel.VerticalScroll.Visible = false; picturePanel.AutoScroll = true; // Chat chatMessageTextBox.KeyPress += new KeyPressEventHandler(Key_Press); chatPanel.HorizontalScroll.Maximum = 0; chatPanel.AutoScroll = false; chatPanel.VerticalScroll.Visible = false; chatPanel.AutoScroll = true; // Start chat chatManager = new ChatManager(); chatManager.Connect(@event.Id, chatPanel); }
private void LoadMainEvents(EventOptions options) { eventGridPanel.Controls.Clear(); // Get events List <EventBrief> events = Program.DataProvider.GetEventsBrief(options); List <int> scores = new List <int>(); List <double> distances = new List <double>(); // Filter invisible if (!showInvisibleEventsCheckBox.Checked) { events = events.Where(item => item.Visible).ToList(); } // Calculate distances UserData user = Program.UserDataManager.GetData(); bool isAddressAdded = !(user.Address == "" || user.Address == null || (user.Latitude == 0 && user.Longitude == 0)); foreach (var evBrief in events) { distances.Add(MathSupplement.Distance(user.Latitude, user.Longitude, evBrief.Latitude, evBrief.Longitude)); } if (options.Keywords.Count > 0) { // Calculate scores KeywordFinder kFinder = new KeywordFinder(); foreach (var evBrief in events) { DataList @event = evBrief.ToDataList(); scores.Add(kFinder.Find(options.Keywords.ToArray(), @event)); } // Sort by score EventBrief[] eventArray = events.ToArray(); int[] scoreArray = scores.ToArray(); Array.Sort(scoreArray, eventArray); events = eventArray.ToList(); scores = scoreArray.ToList(); events.Reverse(); scores.Reverse(); } else { // Sort by distance EventBrief[] eventArray = events.ToArray(); double[] distanceArray = distances.ToArray(); Array.Sort(distanceArray, eventArray); events = eventArray.ToList(); distances = distanceArray.ToList(); } // Grid variables int COL_COUNT = 3; int ROW_COUNT = (events.Count + COL_COUNT - 1) / COL_COUNT; int IMAGE_WIDTH = 304; int IMAGE_HEIGHT = 171; int BANNER_HEIGHT = 60; int START_HEIGHT = 350; int MARGINS = (1000 - IMAGE_WIDTH * COL_COUNT) / (COL_COUNT + 1); // Calculate size of event grid panel eventGridPanel.Size = new Size(1000, MARGINS + (IMAGE_HEIGHT + BANNER_HEIGHT + MARGINS) * ROW_COUNT); eventGridPanel.Location = new Point(0, START_HEIGHT); mainPanel.Size = new Size(1000, START_HEIGHT + eventGridPanel.Size.Height); // Add all of them to a list int col = 0; int count = 0; foreach (var eBrief in events) { // Skip events with 0 score if (scores.Count > 0) { if (scores[count] == 0) { count++; continue; } } // Main container Panel eventPanel = new Panel(); eventPanel.AutoSize = false; eventPanel.Size = new Size(IMAGE_WIDTH, IMAGE_HEIGHT + BANNER_HEIGHT); eventPanel.BorderStyle = BorderStyle.FixedSingle; eventPanel.Click += (sender, e) => { try { mainForm.ShowPanel(new UiEventDisplayPanel(eBrief.Id, this)); //new UiEventDisplay(eBrief.Id, this).Show(); } catch { mainForm.ShowPanel(this); } }; // Calculate position of event panel eventPanel.Location = new Point ( MARGINS + (IMAGE_WIDTH + MARGINS) * col, (IMAGE_HEIGHT + BANNER_HEIGHT + MARGINS) * (count / 3) ); // Thumbnail PictureBox thumbnail = new PictureBox(); thumbnail.Size = new Size(IMAGE_WIDTH, IMAGE_HEIGHT); thumbnail.Location = new Point(0, 0); thumbnail.Click += (sender, e) => { try { mainForm.ShowPanel(new UiEventDisplayPanel(eBrief.Id, this)); //new UiEventDisplay(eBrief.Id, this).Show(); } catch { } }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { try { using (WebClient client = new WebClient()) { Stream stream = client.OpenRead(eBrief.Images[0]); Bitmap bitmap = new Bitmap(stream); thumbnail.Image = Helper.ScaleBitmap(bitmap, IMAGE_WIDTH, IMAGE_HEIGHT, 16.0f / 9.0f); stream.Flush(); stream.Close(); } } catch { } }; worker.RunWorkerAsync(); // Info panel Panel infoPanel = new Panel(); infoPanel.Location = new Point(0, IMAGE_HEIGHT); infoPanel.Size = new Size(IMAGE_WIDTH, BANNER_HEIGHT); if (!eBrief.Visible) { infoPanel.BackColor = Color.FromArgb(255, 200, 200); } // Name label Label eventName = new Label(); eventName.Text = eBrief.Name; eventName.AutoSize = false; eventName.Location = new Point(10, 0); eventName.Size = new Size(IMAGE_WIDTH - 20, 30); //eventName.Font = new Font("Segoe UI Semibold", 12); eventName.Font = new Font("Arial", 12); eventName.ForeColor = Color.FromArgb(16, 16, 16); //eventName.BackColor = Color.White; eventName.TextAlign = ContentAlignment.MiddleLeft; int attempt = 0; while (true) { Size nameSize = Helper.CalculateLabelSize(eventName, 1000); if (nameSize.Width > eventName.Size.Width - 20) { eventName.Text = eventName.Text.Remove(eventName.Text.Length - 1); attempt++; continue; } else { if (attempt != 0) { eventName.Text += "..."; // Create tooltip ToolTip fullEventName = new ToolTip(); fullEventName.SetToolTip(eventName, eBrief.Name); } break; } } // Distance label Label distanceLabel = new Label(); distanceLabel.Font = new Font("Arial", 9); distanceLabel.ForeColor = Color.Gray; distanceLabel.Location = new Point(10, 25); distanceLabel.AutoSize = false; distanceLabel.TextAlign = ContentAlignment.MiddleCenter; double distance = MathSupplement.Distance(eBrief.Latitude, eBrief.Longitude, user.Latitude, user.Longitude); if (distance < 1000.0) { distanceLabel.Text = $"{distance:0}m"; } else { distanceLabel.Text = $"{distance / 1000.0:0.0}km"; } Size distanceLabelSize = Helper.CalculateLabelSize(distanceLabel, IMAGE_WIDTH); distanceLabel.Size = new Size(distanceLabelSize.Width, 30); // Separator panel Panel separatorPanel1 = new Panel(); separatorPanel1.Location = new Point(distanceLabel.Location.X + distanceLabel.Size.Width + 5, 33); separatorPanel1.Size = new Size(1, 16); separatorPanel1.BorderStyle = BorderStyle.FixedSingle; // Sport label Label sportLabel = new Label(); sportLabel.Font = new Font("Arial", 9); sportLabel.ForeColor = Color.Gray; sportLabel.Location = new Point(distanceLabel.Location.X + distanceLabel.Size.Width + 12, 25); sportLabel.AutoSize = false; sportLabel.TextAlign = ContentAlignment.MiddleCenter; try { sportLabel.Text = eBrief.Sports[0]; } catch { sportLabel.Text = ""; } Size sportLabelSize = Helper.CalculateLabelSize(sportLabel, IMAGE_WIDTH); sportLabel.Size = new Size(sportLabelSize.Width, 30); // Separator panel Panel separatorPanel2 = new Panel(); separatorPanel2.Location = new Point(sportLabel.Location.X + sportLabel.Size.Width + 5, 33); separatorPanel2.Size = new Size(1, 16); separatorPanel2.BorderStyle = BorderStyle.FixedSingle; // Date label Label dateLabel = new Label(); dateLabel.Font = new Font("Arial", 9); dateLabel.ForeColor = Color.Gray; dateLabel.Location = new Point(sportLabel.Location.X + sportLabel.Size.Width + 12, 25); dateLabel.AutoSize = false; dateLabel.TextAlign = ContentAlignment.MiddleCenter; { // Create date/time label string finalString = ""; if ((DateTime.Now - eBrief.StartDate).Ticks > 0) { int daysAgo = (DateTime.Now - eBrief.StartDate).Days; finalString += $"Happened "; if (daysAgo == 0) { finalString += "today"; } else if (daysAgo == 1) { finalString += $"{daysAgo} day ago"; } else { finalString += $"{daysAgo} days ago"; } } else { if (eBrief.StartDate.Year != DateTime.Now.Year) { finalString += $"{eBrief.StartDate:yyyy-MM-dd HH:mm}"; } else { if ((eBrief.StartDate - DateTime.Now).TotalDays == 1) { finalString += $"Tomorrow, {eBrief.StartDate:HH:mm}"; } else if ((eBrief.StartDate - DateTime.Now).TotalDays < 1) { finalString += $"Today, {eBrief.StartDate:HH:mm}"; } else { finalString += $"{eBrief.StartDate:MMMM dd, HH:mm}"; } } } dateLabel.Text = finalString; } Size dateLabelSize = Helper.CalculateLabelSize(dateLabel, IMAGE_WIDTH); dateLabel.Size = new Size(dateLabelSize.Width, 30); infoPanel.Controls.Add(eventName); infoPanel.Controls.Add(distanceLabel); infoPanel.Controls.Add(separatorPanel1); infoPanel.Controls.Add(sportLabel); infoPanel.Controls.Add(separatorPanel2); infoPanel.Controls.Add(dateLabel); //// Sport label //Label eventSports = new Label(); //eventSports.Text = ""; //eventSports.Font = new Font("Arial", 11); //foreach (var sport in eBrief.Sports) //{ // eventSports.Text += $"{sport} "; //} //eventSports.AutoSize = false; //eventSports.Location = new Point(0, 210); //eventSports.Size = new Size(180, 25); //eventSports.BackColor = Color.FromArgb(230, 230, 230); //eventSports.TextAlign = ContentAlignment.MiddleLeft; //// Distance label //Label eventDistance = new Label(); //eventDistance.Text = ""; //eventDistance.Font = new Font("Arial", 11, FontStyle.Bold); //eventDistance.Text += $"{distances[count] / 1000.0:0.0}km"; //eventDistance.AutoSize = false; //eventDistance.Location = new Point(180, 210); //eventDistance.Size = new Size(60, 25); //eventDistance.BackColor = Color.FromArgb(230, 230, 230); //eventDistance.TextAlign = ContentAlignment.MiddleCenter; //if (!isAddressAdded) //{ // eventDistance.Text = ""; //} // Add everything eventPanel.Controls.Add(thumbnail); eventPanel.Controls.Add(infoPanel); //eventPanel.Controls.Add(eventSports); //eventPanel.Controls.Add(eventDistance); eventGridPanel.Controls.Add(eventPanel); col = (++col) % COL_COUNT; count++; if (mainForm != null) { mainForm.FitCurrentPanel(); } // Redraw Invalidate(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.event_view); eventName = FindViewById <TextView>(Resource.Id.txtEventName); eventDistance = FindViewById <TextView>(Resource.Id.txtEventDistance); eventAddress = FindViewById <TextView>(Resource.Id.txtEventAddress); eventLocate = FindViewById <ImageView>(Resource.Id.imgLocate); eventImages = FindViewById <LinearLayout>(Resource.Id.lnlImages); eventDescription = FindViewById <TextView>(Resource.Id.txtDescription); horizontalScroll = FindViewById <HorizontalScrollView>(Resource.Id.scrIEventImages); eventNewComment = FindViewById <EditText>(Resource.Id.edtNewComment); eventSubmitComment = FindViewById <ImageButton>(Resource.Id.btnSubmitComment); commentListView = FindViewById <RecyclerView>(Resource.Id.commentRecyclerView); // Get event info eventID = Intent.GetIntExtra("eventID", 0); var @event = RequestSender.GetFullEvent(eventID); // Setting the distance eventLatitude = @event.Latitude; eventLongitude = @event.Longitude; var userLocation = Geolocation.GetLastKnownLocationAsync(); double distance = MathSupplement.Distance(eventLatitude, eventLongitude, userLocation.Result.Latitude, userLocation.Result.Longitude); if (userLocation != null) { if (distance < 1000.0) { eventDistance.Text = $"{distance:0}m"; } else { eventDistance.Text = $"{distance / 1000.0:0.0}km"; } } // Event name and address eventName.Text = @event.Name; eventAddress.Text = @event.Address.Address; // Images int imageWidth = 700; int imageHeight = 450; float aspect; foreach (var item in @event.Images) { Bitmap img; Bitmap scaledImg = Bitmap.CreateBitmap(imageWidth, imageHeight, Bitmap.Config.Argb8888); ImageView imgView = new ImageView(this); imgView.SetImageBitmap(scaledImg); LinearLayout.LayoutParams imgViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent, 0.0f); imgViewParams.SetMargins(16, 16, 16, 16); imgView.LayoutParameters = imgViewParams; eventImages.AddView(imgView); Thread imageLoader = new Thread(new ThreadStart(() => { try { using var webClient = new WebClient(); var imageBytes = webClient.DownloadData(item); if (imageBytes != null && imageBytes.Length > 0) { img = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length); scaledImg = Helper.ScaleBitmap(img, imageWidth, imageHeight); imgView.Alpha = 0.0f; imgView.SetImageBitmap(scaledImg); imgView.Animate().Alpha(1.0f); } } catch { } })); imageLoader.Start(); } // Event description eventDescription.Text = @event.Description; // Check if eligible to comment if (!RequestSender.ThisAccount().Can((uint)WebApi.Classes.Permissions.SEND_CHAT_MESSAGES)) { eventNewComment.Enabled = false; eventSubmitComment.Enabled = false; } else { eventNewComment.Enabled = true; eventSubmitComment.Enabled = true; } // Print comment amount Toast.MakeText(this, RequestSender.GetComments(eventID).Count.ToString(), ToastLength.Short).Show(); // Send comment button eventSubmitComment.Click += (o, e) => { RequestSender.CreateComment(eventID, eventNewComment.Text); eventNewComment.Text = ""; Toast.MakeText(this, "Comment submited!", ToastLength.Short).Show(); }; // Load comments List <WebApi.Classes.Message> comments = RequestSender.GetComments(eventID); var tempMsg = new WebApi.Classes.Message() { Content = "baaaaaadd ddddddddd ddddddddd ddddddddd ddddddddddaaaa ababooe", Sender = 1, SendTime = DateTime.Now, Id = 1 }; comments.Add(tempMsg); tempMsg = new WebApi.Classes.Message() { Content = "KRINDŽAS 🤣🤣🤣🤣", Sender = 2, SendTime = DateTime.Now, Id = 2 }; comments.Add(tempMsg); tempMsg = new WebApi.Classes.Message() { Content = "baaaaaadd", Sender = 3, SendTime = DateTime.Now, Id = 3 }; comments.Add(tempMsg); commentListView.HasFixedSize = true; commentListLayout = new LinearLayoutManager(this); commentListView.SetLayoutManager(commentListLayout); commentListAdapter = new CommentListAdapter(comments); commentListView.SetAdapter(commentListAdapter); }