2021-10-02 00:49:50 +02:00
enum ESortColumn {
ItemName ,
Type ,
Source ,
Size ,
Count
}
bool menu_visibility = false ;
2022-04-08 18:43:56 +02:00
uint camerafocusindex = 0 ;
2021-10-02 00:49:50 +02:00
bool include_default_objects = false ;
bool refreshobject ;
2022-10-13 12:04:36 +02:00
string searchStr = "" ;
2021-10-02 00:49:50 +02:00
bool sort_reverse ;
bool forcesort ;
string infotext ;
array < Objects @ > objects = {};
array < Objects @ > sortableobjects = {};
array < string > objectsindex = {};
ESortColumn sortCol = ESortColumn ( - 1 );
void Main () {
while ( true ) {
if ( refreshobject ) {
objects . Resize ( 0 );
objectsindex . Resize ( 0 );
sortableobjects . Resize ( 0 );
RefreshBlocks ();
RefreshItems ();
sortableobjects = objects ;
2022-11-03 21:38:13 +01:00
if ( sortableobjects . Length > 0 ) sortableobjects . Sort ( function ( a , b ) { return a . size > b . size ; }); // Sort by size by default, it will be used as second sort criteria
2021-10-02 00:49:50 +02:00
refreshobject = false ;
}
yield ();
}
}
2022-10-13 12:04:36 +02:00
void RenderInterface () {
if ( ! menu_visibility ) return ;
if ( ! RenderLib :: InMapEditor ()) return ;
2022-07-20 19:44:13 +02:00
CGameCtnEditorFree @ editor = cast < CGameCtnEditorFree > ( GetApp (). Editor );
CGameCtnChallenge @ map = cast < CGameCtnChallenge > ( GetApp (). RootMap );
2021-10-02 00:49:50 +02:00
infotext = "" ;
UI :: SetNextWindowPos ( 200 , 200 , UI :: Cond :: Once );
2022-10-13 12:04:36 +02:00
UI :: PushStyleVar ( UI :: StyleVar :: WindowMinSize , vec2 ( 600 , 400 ));
if ( UI :: Begin ( "\\$cf9" + Icons :: Table + "\\$z Blocks & Items Counter###Blocks & Items Counter" , menu_visibility , UI :: WindowFlags :: NoCollapse )) {
2021-10-02 00:49:50 +02:00
if ( refreshobject ) {
2022-10-13 12:04:36 +02:00
RenderLib :: LoadingButton ();
2021-10-02 00:49:50 +02:00
} else {
2022-10-13 12:04:36 +02:00
if ( UI :: Button ( Icons :: Refresh + " Refresh" )) {
2021-10-02 00:49:50 +02:00
refreshobject = true ;
forcesort = true ;
}
}
UI :: SameLine ();
2022-10-13 12:04:36 +02:00
UI :: PushStyleColor ( UI :: Col :: FrameBg , vec4 ( 0.169 , 0.388 , 0.651 , 0.1 ));
2021-10-02 00:49:50 +02:00
include_default_objects = UI :: Checkbox ( "Include In-Game Blocks and Items" , include_default_objects );
2022-10-13 12:04:36 +02:00
UI :: SameLine ();
UI :: Dummy ( vec2 ( UI :: GetWindowSize (). x - 600 , 10 ));
UI :: SameLine ();
UI :: SetNextItemWidth ( 200 );
if ( refreshobject ) {
searchStr = "" ;
string newSearchStr = UI :: InputText ( "Filter" , searchStr , UI :: InputTextFlags ( UI :: InputTextFlags :: AutoSelectAll | UI :: InputTextFlags :: NoUndoRedo | UI :: InputTextFlags :: ReadOnly ));
} else {
string newSearchStr = UI :: InputText ( "Filter" , searchStr , UI :: InputTextFlags ( UI :: InputTextFlags :: AutoSelectAll | UI :: InputTextFlags :: NoUndoRedo ));
if ( newSearchStr != searchStr ) {
searchStr = newSearchStr ;
string searchStrLower = searchStr . ToLower ();
sortableobjects = {};
for ( uint i = 0 ; i < objects . Length ; i ++ ) {
if ( searchStrLower == "" || objects [ i ]. name . ToLower (). Contains ( searchStrLower )) {
sortableobjects . InsertLast ( objects [ i ]);
}
}
}
}
UI :: PopStyleColor ();
2021-10-02 00:49:50 +02:00
UI :: Separator ();
vec2 winsize = UI :: GetWindowSize ();
winsize . x = winsize . x - 10 ;
winsize . y = winsize . y - 105 ;
2022-10-13 12:04:36 +02:00
if ( UI :: BeginTable ( "ItemsTable" , 5 , UI :: TableFlags ( UI :: TableFlags :: Resizable | UI :: TableFlags :: Sortable | UI :: TableFlags :: NoSavedSettings | UI :: TableFlags :: BordersInnerV | UI :: TableFlags :: SizingStretchProp | UI :: TableFlags :: ScrollY ) , winsize )) { UI :: TableSetupScrollFreeze ( 0 , 1 );
2021-10-02 00:49:50 +02:00
UI :: TableSetupColumn ( "Item Name" , UI :: TableColumnFlags :: None , 55 . f , ESortColumn :: ItemName );
UI :: TableSetupColumn ( "Type" , UI :: TableColumnFlags :: None , 7 . f , ESortColumn :: Type );
UI :: TableSetupColumn ( "Source" , UI :: TableColumnFlags :: None , 13 . f , ESortColumn :: Source );
UI :: TableSetupColumn ( "Size" , UI :: TableColumnFlags :: None , 15 . f , ESortColumn :: Size );
UI :: TableSetupColumn ( "Count" , UI :: TableColumnFlags :: DefaultSort , 10 . f , ESortColumn :: Count );
UI :: TableHeadersRow ();
UI :: TableSortSpecs @ sortSpecs = UI :: TableGetSortSpecs ();
if ( sortSpecs ! is null && sortSpecs . Specs . Length == 1 && sortableobjects . Length > 1 ) {
if ( sortSpecs . Dirty || ( forcesort && ! refreshobject )) {
if ( sortCol != ESortColumn ( sortSpecs . Specs [ 0 ]. ColumnUserID ) || ( forcesort && ! refreshobject )) {
sortCol = ESortColumn ( sortSpecs . Specs [ 0 ]. ColumnUserID );
switch ( sortCol ) {
case ESortColumn :: ItemName :
sortableobjects . Sort ( function ( a , b ) { return a . name < b . name ; });
break ;
case ESortColumn :: Type :
sortableobjects . Sort ( function ( a , b ) { return a . type < b . type ; });
break ;
case ESortColumn :: Source :
sortableobjects . Sort ( function ( a , b ) { return a . source < b . source ; });
break ;
case ESortColumn :: Size :
sortableobjects . Sort ( function ( a , b ) { return a . size < b . size ; });
break ;
case ESortColumn :: Count :
sortableobjects . Sort ( function ( a , b ) { return a . count < b . count ; });
break ;
}
if ( forcesort && sort_reverse ) {
sortableobjects . Reverse ();
} else {
sort_reverse = false ;
}
} else if ( sortCol == ESortColumn ( sortSpecs . Specs [ 0 ]. ColumnUserID )) {
sortableobjects . Reverse ();
sort_reverse = ! sort_reverse ;
}
sortSpecs . Dirty = false ;
forcesort = false ;
}
}
if ( sortableobjects . Length > 0 ) {
2022-04-08 18:43:56 +02:00
for ( uint i = 0 ; i < sortableobjects . Length ; i ++ ) {
2022-10-13 12:04:36 +02:00
RenderLib :: GenerateRow ( sortableobjects [ i ]);
2021-10-02 00:49:50 +02:00
}
2022-10-13 12:04:36 +02:00
} else if ( refreshobject ) { // Display the items during the refresh
2022-04-08 18:43:56 +02:00
for ( uint i = 0 ; i < objects . Length ; i ++ ) {
2022-10-13 12:04:36 +02:00
RenderLib :: GenerateRow ( objects [ i ]);
2021-10-02 00:49:50 +02:00
}
}
UI :: EndTable ();
UI :: Separator ();
UI :: Text ( Icons :: Info + " " + infotext );
}
}
2022-10-13 12:04:36 +02:00
UI :: End ();
UI :: PopStyleVar ();
2021-10-02 00:49:50 +02:00
}
void RenderMenu () {
2022-10-13 12:04:36 +02:00
if ( ! RenderLib :: InMapEditor ()) return ;
2022-07-20 19:44:13 +02:00
2021-10-02 00:49:50 +02:00
if ( UI :: MenuItem ( "\\$cf9" + Icons :: Table + "\\$z Blocks & Items Counter" , "" , menu_visibility )) {
menu_visibility = ! menu_visibility ;
refreshobject = true ;
2022-10-13 12:04:36 +02:00
forcesort = true ;
2021-10-02 00:49:50 +02:00
}
}