Skip to content

Commit

Permalink
Able to get other employee easily
Browse files Browse the repository at this point in the history
  • Loading branch information
geoje committed May 29, 2021
1 parent 8097ad2 commit 9f4810b
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 42 deletions.
10 changes: 8 additions & 2 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@
<None Include="Resources\back.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\department.png" />
<None Include="Resources\treenode.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\treenode.png" />
<None Include="Resources\central.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\office-building.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\team.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
33 changes: 15 additions & 18 deletions Client/Forms/ControlRoom.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 32 additions & 3 deletions Client/Forms/ControlRoom.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
using MetroFramework.Controls;
using Client.Properties;
using MetroFramework.Controls;
using OSTLibrary.Chats;
using System;
using System.Drawing;

namespace Client.Forms
{
public partial class ControlRoom : MetroUserControl
{
public ControlRoom()
public DateTime dclick;

public ControlRoom(Room room)
{
InitializeComponent();

picProfile.Image =
room.scopeIdx == 0 ? Resources.office_building :
room.scopeIdx == 1 ? Resources.central :
room.scopeIdx == 2 ? Resources.team :
room.scopeIdx == 3 ? room.GetOtherEmployee(Program.employee).profile :
Resources.profile;
}

private void ControlRoom_MouseEnter(object sender, EventArgs e)
Expand All @@ -17,7 +28,25 @@ private void ControlRoom_MouseEnter(object sender, EventArgs e)
}
private void ControlRoom_MouseLeave(object sender, EventArgs e)
{
BackColor = Color.Transparent;
if (ClientRectangle.Contains(PointToClient(MousePosition)))
return;
BackColor = Color.White;
}

public void UpdateInfo(Chat chat)
{
lblChat.Text =
chat.type == ChatType.Text ? chat.text :
chat.type == ChatType.Image ? "사진" : "";

if (chat.date.Year < DateTime.Now.Year)
lblTime.Text = $"{DateTime.Now.Year - chat.date.Year}년 전";
else if (chat.date.Month < DateTime.Now.Month)
lblTime.Text = $"{DateTime.Now.Month - chat.date.Month}달 전";
else if (chat.date.Day < DateTime.Now.Day)
lblTime.Text = $"{DateTime.Now.Month - chat.date.Month}일 전";
else
lblTime.Text = chat.date.ToShortTimeString();
}
}
}
47 changes: 33 additions & 14 deletions Client/Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ namespace Client.Forms
{
public partial class FormMain : MetroForm
{
List<FormChat> formChats;
Dictionary<string, FormChat> formChats;
Dictionary<string, ControlRoom> controlRooms;

public FormMain()
{
InitializeComponent();

formChats = new List<FormChat>();
Opacity = 0;
}
private void FormMain_Shown(object sender, EventArgs e)
Expand All @@ -38,7 +37,10 @@ private void FormMain_Shown(object sender, EventArgs e)
picProfile.Image = Program.employee.profile;
lblName.Text = Program.employee.name;
lblTeamRank.Text = $"{Program.employee.team} {Program.employee.rank}";
formChats = new List<FormChat>();

// 채팅 관련 컨트롤들 배열 초기화
formChats = new Dictionary<string, FormChat>();
controlRooms = new Dictionary<string, ControlRoom>();

// 최초 룸 모두 추가
Program.rooms.ForEach(AddRoomCard);
Expand Down Expand Up @@ -81,13 +83,13 @@ private void FormMain_Shown(object sender, EventArgs e)
if (room == null)
{
room = new Room("", 3, $"{Program.employee.id},{emp.id}");
formChats.Add(new FormChat(room));
formChats.Add(room.id, new FormChat(room));
Program.Send(new RoomPacket(RoomType.New, room));
}
else
formChats.Add(new FormChat(room));
formChats.Add(room.id, new FormChat(room));

formChats[formChats.Count - 1].Show();
formChats[room.id].Show();
};

// 이미지 인덱스
Expand Down Expand Up @@ -132,12 +134,22 @@ private void lnkSchAdd_Click(object sender, EventArgs e)

void AddRoomCard(Room room)
{
ControlRoom cardRoom = new ControlRoom();
cardRoom.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
pnlChat.Controls.Add(cardRoom);
ControlRoom cardRoom = new ControlRoom(room);
cardRoom.DoubleClick += (sender, e) => {
if (formChats.ContainsKey(room.id))
{
formChats[room.id].Focus();
return;
}

formChats.Add(room.id, new FormChat(room));
formChats[room.id].Show();
};
if (room.chats.Count > 0)
cardRoom.UpdateInfo(room.chats[room.chats.Count - 1]);

cardRoom = new ControlRoom();
pnlChat.Controls.Add(cardRoom);
controlRooms.Add(room.id, cardRoom);
}
void ReceiveRoom(Packet p)
{
Expand All @@ -146,13 +158,20 @@ void ReceiveRoom(Packet p)
Program.rooms.Add(rp.room);
AddRoomCard(rp.room);

FormChat fc = formChats.Find(form => form.room == null);
if (fc != null) fc.room = rp.room;
if (formChats.ContainsKey(""))
{
FormChat fc = formChats[""];
formChats.Remove("");
fc.room = rp.room;
formChats.Add(fc.room.id, fc);
}
}
void ReceiveChat(Packet p)
{
ChatsPacket cp = p as ChatsPacket;
formChats.Find(fc => fc.room.id == cp.chats[0].room.id).ReceiveChat(cp);

if (formChats.ContainsKey(""))
formChats[cp.chats[0].room.id].ReceiveChat(cp);
}
}
}
24 changes: 22 additions & 2 deletions Client/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Client/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@
<data name="settings" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\settings.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="department" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\department.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="central" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\central.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="office_building" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\office-building.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="team" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\team.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Client/Resources/central.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Client/Resources/department.png
Binary file not shown.
Binary file added Client/Resources/office-building.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/Resources/team.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion OSTLibrary/Chats/Room.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using OSTLibrary.Classes;
using System;
using System.Collections.Generic;

namespace OSTLibrary.Chats
Expand All @@ -11,6 +12,7 @@ public class Room
public string id;
public int scopeIdx;
public string target;

public List<Chat> chats;

public Room(string id, int scopeIdx, string target)
Expand All @@ -20,5 +22,20 @@ public Room(string id, int scopeIdx, string target)
this.target = target;
chats = new List<Chat>();
}

public int GetOtherEmployeeId(Employee myEmp)
{
if (scopeIdx != 3)
return 0;

foreach(string empStr in target.Split(','))
{
if (empStr == myEmp.id.ToString())
continue;

return int.Parse(empStr);
}
return 0;
}
}
}

0 comments on commit 9f4810b

Please sign in to comment.