Skip to content

Commit

Permalink
Merged PR 369: Merge 496_remove_tree_nodes_from_menu to master
Browse files Browse the repository at this point in the history
Related work items: #496
  • Loading branch information
Allen B. Cummings committed Nov 16, 2018
1 parent 1f5433a commit 9e9b4b3
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 87 deletions.
67 changes: 49 additions & 18 deletions dictionaries/researchDictionary.c
Expand Up @@ -739,6 +739,23 @@ private nomask mapping buildResearchList(string *researchList,
return ret;
}

/////////////////////////////////////////////////////////////////////////////
private nomask mapping getTreeMenuItem(object tree, int index)
{
mapping ret = ([]);
string name = tree->Name() || "UNDEFINED";
if (sizeof(name) > 20)
{
name = name[0..16] + "...";
}
ret[to_string(index)] = ([
"name":capitalize(name),
"description": tree->Description(),
"type": program_name(tree)
]);
return ret;
}

/////////////////////////////////////////////////////////////////////////////
private nomask varargs mapping buildResearchTreeList(string *trees,
string type, object user, int startIndex, int hideTree)
Expand All @@ -754,16 +771,7 @@ private nomask varargs mapping buildResearchTreeList(string *trees,

if (!hideTree)
{
string name = treeObj->Name() || "UNDEFINED";
if (sizeof(name) > 20)
{
name = name[0..16] + "...";
}
ret[to_string(index)] = ([
"name":capitalize(name),
"description" : treeObj->Description(),
"type" : tree
]);
ret += getTreeMenuItem(treeObj, index);
index++;
}
object *researchList = sort_array(
Expand Down Expand Up @@ -792,20 +800,43 @@ private nomask varargs mapping buildResearchTreeList(string *trees,
}

/////////////////////////////////////////////////////////////////////////////
public nomask mapping getResearchOfType(string type, object user)
public nomask mapping getResearchOfType(string type, object user, int showTreeElements)
{
mapping ret = ([]);

if (stringp(type) && objectp(user))
{
ret = buildResearchList(sort_array(user->completedResearch() +
user->researchInProgress(), (: $1 > $2 :)), sizeof(ret) + 1,
user, type);
string *trees = filter(user->availableResearchTrees(),
(: $1->Source() == $2 :), type);

ret += buildResearchTreeList(
filter(user->availableResearchTrees(),
(: $1->Source() == $2 :), type),
type, user, sizeof(ret) + 1);
string *research = user->completedResearch() +
user->researchInProgress();

if (showTreeElements)
{
ret += buildResearchTreeList(
filter(user->availableResearchTrees(),
(: $1->Source() == $2 :), type),
type, user, sizeof(ret) + 1);
}
else
{
int index = 1;
foreach(string tree in trees)
{
object treeObj = researchTree(tree);
if (treeObj)
{
research = filter(research,
(: !$2->isMemberOfResearchTree($1) :), treeObj);
}
ret += getTreeMenuItem(treeObj, index);
index++;
}
}
ret += buildResearchList(sort_array(research,
(: $1 > $2 :)), sizeof(ret) + 1,
user, type);
}
return ret;
}
Expand Down
13 changes: 13 additions & 0 deletions modules/research/researchSelector.c
Expand Up @@ -7,6 +7,13 @@ inherit "/lib/core/baseSelector.c";
private int TotalPoints;
private object SubselectorObj;
private object Dictionary;
private int ShowTreeElements;

/////////////////////////////////////////////////////////////////////////////
public nomask void showTreeElements()
{
ShowTreeElements = 1;
}

/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
Expand Down Expand Up @@ -75,6 +82,12 @@ protected nomask int processSelection(string selection)
SubselectorObj = clone_object("/lib/modules/research/researchSubselector.c");
move_object(SubselectorObj, User);
SubselectorObj->setSource(Data[selection]["type"]);

if (ShowTreeElements)
{
SubselectorObj->showTreeElements();
}

SubselectorObj->registerEvent(this_object());
SubselectorObj->setPointsRemaining(TotalPoints);
SubselectorObj->initiateSelector(User);
Expand Down
9 changes: 8 additions & 1 deletion modules/research/researchSubselector.c
Expand Up @@ -8,13 +8,20 @@ private object Dictionary;
private string Source;
private object SubselectorObj;
private int TotalPoints;
private int ShowTreeElements;

/////////////////////////////////////////////////////////////////////////////
public nomask void setSource(string source)
{
Source = source;
}

/////////////////////////////////////////////////////////////////////////////
public nomask void showTreeElements()
{
ShowTreeElements = 1;
}

/////////////////////////////////////////////////////////////////////////////
protected mapping researchMenuSetup(string type)
{
Expand Down Expand Up @@ -65,7 +72,7 @@ protected mapping researchMenuSetup(string type)
else if (!sizeof(menu))
{
NumColumns = 2;
menu = Dictionary->getResearchOfType(type, User);
menu = Dictionary->getResearchOfType(type, User, ShowTreeElements);
}
return menu + ([]);
}
Expand Down

0 comments on commit 9e9b4b3

Please sign in to comment.