source: cpp/frams/userinput/modelcheckpoints.cpp @ 1156

Last change on this file since 1156 was 999, checked in by Maciej Komosinski, 4 years ago

More consistent usage of "shapetype" (vs. "shape")

File size: 3.6 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "modelcheckpoints.h"
6
7ModelCheckpointSupport::ModelCheckpointSupport(ModelSelectionPropagator &msp, ModelViewInterface &_model_view)
8        :mod_sel_prop(msp), model_view(_model_view), mod(NULL), mod_checkpoints(NULL)
9{
10        selection_enabled = false;
11}
12
13ModelCheckpointSupport::~ModelCheckpointSupport()
14{
15        freeModel();
16}
17
18void ModelCheckpointSupport::enableSelection(bool e)
19{
20        if (e == selection_enabled) return;
21        selection_enabled = e;
22        if (selection_enabled)
23        {
24                mod_sel_prop.addModelSelection(&model_view.getModelSelection());
25                mod_sel_prop.setModel(mod);
26        }
27        else
28        {
29                mod_sel_prop.removeModelSelection(&model_view.getModelSelection());
30                mod_sel_prop.setModel(NULL);
31        }
32
33}
34
35void ModelCheckpointSupport::freeModel()
36{
37        enableSelection(false);
38        SAFEDELETE(mod);
39        SAFEDELETE(mod_checkpoints);
40}
41
42int ModelCheckpointSupport::showGeno(const Geno* g, bool _use_checkpoints)
43{
44        use_checkpoints = (g != NULL) && _use_checkpoints;
45        freeModel();
46        if (g != NULL)
47                mod = new Model(*g, Model::SHAPETYPE_UNKNOWN, true, false);
48        toguiCheckpoints(use_checkpoints ? EnabledUnknown : Disabled, 1, 1);
49        int ret = model_view.showModel(mod);
50        enableSelection(true);
51        return ret;
52}
53
54void ModelCheckpointSupport::fromguiPhase(float p)
55{
56        if (mod == NULL) return;
57        if (use_checkpoints && (mod_checkpoints == NULL))
58        {
59                if (p == current_value) return;
60                mod_checkpoints = new Model(mod->getGeno(), Model::SHAPETYPE_UNKNOWN, false, true);
61                if (mod_checkpoints->getCheckpointCount() > 1)
62                {
63                        max_value = current_value = mod_checkpoints->getCheckpointCount() - 1;
64                        current_index = mod_checkpoints->getCheckpointCount();
65                        toguiCheckpoints(EnabledActive, current_value, current_value);
66                }
67                else
68                {
69                        toguiCheckpoints(EnabledUnavailable, 1, 1);
70                }
71        }
72
73        if (!(mod_checkpoints->getCheckpointCount() > 1))
74                return;
75
76        current_value = p;
77        int i = int(current_value + 0.5);
78        if (current_value == max_value)
79                i = mod_checkpoints->getCheckpointCount();
80        if (i != current_index)
81        {
82                current_index = i;
83                if (current_index < mod_checkpoints->getCheckpointCount())
84                {
85                        model_view.showModel(mod_checkpoints->getCheckpoint(i));
86                        enableSelection(false);
87                }
88                else
89                {
90                        model_view.showModel(mod);
91                        enableSelection(true);
92                }
93        }
94}
95
96int ModelCheckpointSupport::showModel(const Model *m)
97{
98        freeModel();
99        return model_view.showModel(m);
100}
101
102Model *ModelCheckpointSupport::getModel()
103{
104        return mod ? mod : model_view.getModel();
105}
106
107ModelSelection& ModelCheckpointSupport::getModelSelection()
108{
109        return model_view.getModelSelection();
110}
111
112ModelCheckpointSupport::CheckpointsMode ModelCheckpointSupport::getCheckpointsMode()
113{
114        if (use_checkpoints)
115        {
116                if (mod_checkpoints == NULL)
117                        return EnabledUnknown;
118                if (mod_checkpoints->getCheckpointCount() > 1)
119                        return EnabledActive;
120                else
121                        return EnabledUnavailable;
122        }
123        else
124                return Disabled;
125}
126
127SString ModelCheckpointSupport::checkpointHint()
128{
129        switch (getCheckpointsMode())
130        {
131        case EnabledUnknown: return SString("Drag horizontally to show developmental phases");
132        case EnabledUnavailable: return SString("Developmental phases not available for this genotype");
133        case EnabledActive:
134                if (current_index < mod_checkpoints->getCheckpointCount())
135                        return SString::sprintf("Displaying developmental phase %d of %d", current_index, mod_checkpoints->getCheckpointCount());
136                else
137                        return SString("Displaying the final phase of development");
138        }
139        return SString();
140}
141
Note: See TracBrowser for help on using the repository browser.