Skip to content

Commit

Permalink
* ADD:[LE] Новый choose form
Browse files Browse the repository at this point in the history
  • Loading branch information
BearIvan committed Jul 3, 2022
1 parent fc252cf commit 07320bc
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 220 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
#pragma once
class XREPROPS_API UIChooseForm :
public XrUI,private FolderHelper<SChooseItem>
class XREPROPS_API UIChooseForm : public XrUI
{
virtual void DrawItem(Node* Node);
friend class UIChooseFormItem;
/* virtual void DrawItem(Node* Node);
virtual bool IsDrawFloder(Node* Node);
void AppendItem(SChooseItem& item);
void UpdateTexture();
Node m_GeneralNode;
Node m_GeneralNode;*/
void UpdateSelected(UIChooseFormItem*NewSelected);
UIChooseFormItem m_RootItem;
ImTextureID m_Texture;
ImGuiTextFilter m_Filter;
private:
int iMultiSelLimit;
int iSelectedInList;
UIPropertiesForm* m_Props;
Flags32 m_Flags;
xr_string m_Title;
xr_vector<SChooseItem*>m_SelectedItems;

inline SChooseItem* GetSelectedItem() { if (m_SelectedItems.size()) { return m_SelectedItems.back(); }return nullptr; }
SChooseItem* m_ClickItem;
SChooseItem* m_SelectedItem;
s32 m_SelectedList;
SChooseItem* GetSelectedItem();
UIChooseFormItem* m_SelectedItem;
SChooseItem m_ItemNone;
ChooseItemVec m_Items;
u32 m_ChooseID;
void FillItems(u32 choose_id);
void CheckFavorite();
protected:

DEFINE_MAP(u32, SChooseEvents, EventsMap, EventsMapIt);
static EventsMap m_Events;
private:
static xr_string m_LastSelection;
SChooseEvents E;
static UIChooseForm* Form;
static ImTextureID NullTexture;
Expand Down
306 changes: 306 additions & 0 deletions Source/Editors/XrEProps/Tree/Choose/UIChooseFormItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
#include "stdafx.h"

UIChooseFormItem::UIChooseFormItem(shared_str Name):Object(nullptr),UITreeItem(Name)
{
bIsFavorite = false;
m_bIsMixed = false;
bSelected = false;
Index = -1;
}

UIChooseFormItem::~UIChooseFormItem()
{
}

void UIChooseFormItem::Draw()
{
if (!CheckFilter())
return;
ImGui::PushID(this);
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (Object)
{
ImGuiTreeNodeFlags Flags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
if (bSelected)
{
Flags |= ImGuiTreeNodeFlags_Bullet;
}
if (Form->m_SelectedItem==this)
{
Flags |= ImGuiTreeNodeFlags_Selected;
}
if (Form->m_Flags.test(cfMultiSelect))
{
if (ImGui::Checkbox("##checkbox", &bIsFavorite))
{
if (bSelected)
{
Form->m_RootItem.SelectedToFavorite(bIsFavorite);
}
else
{
Form->m_RootItem.ClearSelection();
Form->m_SelectedItem = this;
bSelected = true;
}
Form->CheckFavorite();
}
ImGui::SameLine(0, 0);
}
ImGui::TreeNodeEx(Text.c_str(), Flags);
if (ImGui::IsItemClicked())
{
if (Form->m_Flags.test(cfMultiSelect))
{
if (ImGui::GetIO().KeyShift)
{
if (Form->m_SelectedItem)
{
Form->m_RootItem.Selected(Index, Form->m_SelectedItem->Index);
}
bSelected = true;
}
else if (ImGui::GetIO().KeyCtrl)
{
bSelected = true;
Form->UpdateSelected(this);
}
else
{
Form->m_RootItem.ClearSelection();
Form->m_SelectedItem = this;
bSelected = true;
Form->UpdateSelected(this);
}
}
else
{
Form->m_RootItem.ClearSelection();
Form->m_SelectedItem = this;
bSelected = true;
Form->UpdateSelected(this);
}
}
}
else
{
ImGuiTreeNodeFlags Flags = ImGuiTreeNodeFlags_OpenOnArrow;
if (Form->m_Flags.test(cfMultiSelect))
{
ImGui::PushItemFlag(ImGuiItemFlags_MixedValue, m_bIsMixed);
bool CheckChange = ImGui::Checkbox("##checkbox", &bIsFavorite);
ImGui::PopItemFlag();
if (CheckChange)
{
Form->m_RootItem.ClearSelection();
Form->m_SelectedItem = nullptr;
bSelected = false;
SetFavorite(bIsFavorite);
Form->CheckFavorite();
}
ImGui::SameLine(0, 0);
}
if (ImGui::TreeNodeEx(Name.c_str(), Flags))
{
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->Draw();
}
ImGui::TreePop();
}
}

ImGui::PopID();



}

void UIChooseFormItem::DrawRoot()
{
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->Draw();
}
}

void UIChooseFormItem::Sort()
{
for (UITreeItem* Item : Items)
{
std::sort(Items.begin(), Items.end(), [](UITreeItem* Right, UITreeItem* Left)->bool
{
UIChooseFormItem* pRight = ((UIChooseFormItem*)Right);
UIChooseFormItem* pLeft = ((UIChooseFormItem*)Left);
if(pRight->Object&& !pLeft->Object)
{
return false;
}
if (!pRight->Object && pLeft->Object)
{
return true;
}
return xr_strcmp(pRight->Name.c_str(), pLeft->Name.c_str()) < 0;
});
}


for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->Sort();
}
}

void UIChooseFormItem::CheckFavorited()
{
if (Items.size() == 0)return;
if (!Form->m_Flags.test(cfMultiSelect))
{
return;
}
m_bIsMixed = false;
bool bIsLastFavorited = ((UIChooseFormItem*)Items.front())->bIsFavorite;
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->CheckFavorited();
m_bIsMixed |= ((UIChooseFormItem*)Item)->m_bIsMixed;
if (bIsLastFavorited != ((UIChooseFormItem*)Item)->bIsFavorite)
{

bIsLastFavorited = false;
m_bIsMixed = true;
}
}
bIsFavorite = bIsLastFavorited;
}

void UIChooseFormItem::SetFavorite(bool bFavorited)
{
if (!Form->m_Flags.test(cfMultiSelect))
{
return;
}
bIsFavorite = bFavorited;
m_bIsMixed = false;
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->SetFavorite(bFavorited);
}
}

void UIChooseFormItem::FillFavorited(xr_vector<SChooseItem*>& Favorited)
{
if (!Form->m_Flags.test(cfMultiSelect))
{
return;
}
if (Object&&bIsFavorite)
{
Favorited.push_back(Object);
}
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->FillFavorited(Favorited);
}
}

void UIChooseFormItem::CheckFavorited(xr_vector<SChooseItem*>& Favorited)
{
if (!Form->m_Flags.test(cfMultiSelect))
{
return;
}
if (Object)
{
bIsFavorite = std::find_if(Favorited.begin(), Favorited.end(), [&](SChooseItem* I) {return Object == I; })!= Favorited.end();
}
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->CheckFavorited(Favorited);
}
}

void UIChooseFormItem::ClearSelection()
{
bSelected = false;
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->ClearSelection();
}
}

void UIChooseFormItem::Selected(int Start, int End)
{

for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->Selected(Start,End);
}
if (!Object)
{
return;
}
if (!CheckFilter())
{
return;
}

if (Start > End)
std::swap(Start, End);
if (Index >= Start && Index <= End)
bSelected = true;
else
bSelected = false;
}

void UIChooseFormItem::SelectedToFavorite(bool Favorite)
{
if (!Form->m_Flags.test(cfMultiSelect))
{
return;
}
for (UITreeItem* Item : Items)
{
((UIChooseFormItem*)Item)->SelectedToFavorite(Favorite);
}
if (bSelected)
{
SetFavorite(Favorite);
}
}

bool UIChooseFormItem::CheckFilter()
{
if (!Form->m_Filter.InputBuf[0])
{
return true;
}
if (Object)
{
if (Form->m_Filter.PassFilter(Object->name.c_str()))
{
return true;
}

}
else
{
bool bTest = false;
for (UITreeItem* Item : Items)
{
bTest |= ((UIChooseFormItem*)Item)->CheckFilter();
}
return bTest;
}


return false;
}

UITreeItem* UIChooseFormItem::CreateItem(shared_str Name)
{
auto Item = xr_new<UIChooseFormItem>(Name);
Item->Form = Form;
return Item;
}
29 changes: 29 additions & 0 deletions Source/Editors/XrEProps/Tree/Choose/UIChooseFormItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
class UIChooseFormItem :public UITreeItem
{
public:
UIChooseFormItem(shared_str Name);
virtual ~UIChooseFormItem();

bool bIsFavorite;

class UIChooseForm* Form;
int Index;
SChooseItem* Object;
shared_str Text;
bool bSelected;
void Draw();
void DrawRoot();
void Sort();
void CheckFavorited();
void SetFavorite(bool bFavorite);
void FillFavorited(xr_vector< SChooseItem*>& selected);
void CheckFavorited(xr_vector< SChooseItem*>& selected);
void ClearSelection();
void Selected(int Start, int End);
void SelectedToFavorite(bool Favorite);
protected:
bool CheckFilter();
virtual UITreeItem* CreateItem(shared_str Name);
bool m_bIsMixed;
};
Loading

0 comments on commit 07320bc

Please sign in to comment.