Welcome to mirror list, hosted at ThFree Co, Russian Federation.

map_editor.h « Editors « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 203449f713ff0160cae39483cc7a83e27098ccdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//-----------------------------------------------------------------------------
//           Name: map_editor.h
//      Developer: Wolfire Games LLC
//    Description: 
//        License: Read below
//-----------------------------------------------------------------------------
//
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once

#include <Editors/editor_types.h>
#include <Editors/editor_utilities.h>
#include <Editors/editor_tools.h>
#include <Editors/save_state.h>

#include <Internal/collisiondetection.h>
#include <Internal/levelxml.h>

#include <Game/EntityDescription.h>
#include <Online/online_datastructures.h>
#include <GUI/IMUI/imui.h>
#include <Objects/object.h>
#include <XML/level_loader.h>
#include <Math/overgrowth_geometry.h>
#include <UserInput/keyboard.h>

#include <queue>
#include <set>

extern bool draw_group_and_prefab_boxes;
extern bool always_draw_hotspot_connections;

namespace PHOENIX_KEY_CONSTANTS {
    #ifdef PLATFORM_MACOSX
        const int command_key = Keyboard::GUI;
        const int command_SDLK_key = SDLK_GUI;
    #else
        const int command_key = Keyboard::CTRL;
        const int command_SDLK_key = SDLK_CTRL;
    #endif
}

class SceneGraph;
class EnvObject;
class TiXmlDocument;
class TiXmlElement;
class Group;
class ActorsEditor;
class SkyEditor;
class Hotspot;
class DecalObject;
class GUI;
class GameCursor;
class TiXmlNode;
class TerrainObject;

class TypeEnable {
public:
    TypeEnable(const char* config_postfix);
    bool IsTypeEnabled(EntityType type) const;
    void SetTypeEnabled(EntityType type, bool enabled);
    void SetAll(bool enabled);
    void SetFromConfig();
    void WriteToConfig();
private:
    typedef std::map<EntityType, bool> TypeEnabledMap;
    TypeEnabledMap type_enabled_;
    bool unknown_types_enabled_;
    const char* config_postfix;
    bool ReadTypeString(EntityType type);
    void WriteTypeString(EntityType type) const;
};

struct FaceDisplay {
    bool facing, plane;
};

enum ToolMode {
    SCALE_WHOLE,
    SCALE_PLANE,
    SCALE_NORMAL,
    TRANSLATE_CAMERA_PLANE,
    TRANSLATE_FACE_PLANE,
    TRANSLATE_FACE_NORMAL,
    ROTATE_SPHERE,
    ROTATE_CIRCLE
};

inline const char* GetToolModeString( ToolMode m )
{
    switch( m)
    {
        case SCALE_WHOLE:               return "SCALE_WHOLE";
        case SCALE_PLANE:               return "SCALE_PLANE";
        case SCALE_NORMAL:              return "SCALE_NORMAL";
        case TRANSLATE_CAMERA_PLANE:    return "TRANSLATE_CAMERA_PLANE";
        case TRANSLATE_FACE_PLANE:      return "TRANSLATE_FACE_PLANE";
        case TRANSLATE_FACE_NORMAL:     return "TRANSLATE_FACE_NORMAL";
        case ROTATE_SPHERE:             return "ROTATE_SPHERE";
        case ROTATE_CIRCLE:             return "ROTATE_CIRCLE";
        default:                        return "(unknown tool mode string value)";
    }
}

struct Tool {
    ToolMode mode;

    int control_vertex;

    quaternion trackball_accumulate;
    vec3 center;
    vec3 around;
    int old_mousex;
    int old_mousey;
};

struct Basis {
    vec3 up;
    vec3 facing;
    vec3 right;
};

struct ControlEditorInfo {
    vec3 start_cam_pos;
    LineSegment start_mouseray_;
    vec3 clicked_point_;
    Basis basis_;
    int face_selected_;
    FaceDisplay face_display_;

    Tool tool_;
};

// The MapEditor class contains all of the editors.
class MapEditor {
public:
    MapEditor();
    ~MapEditor();

    enum State {
        kInGame,
        kIdle,
        kTransformDrag,
        kBoxSelectDrag,
        kSkyDrag
    };

    State state_;
    GUI* gui;


    void Initialize(SceneGraph* s);
    void UpdateEnabledObjects();

    void Draw();
    void Update(GameCursor* cursor);

    void ShowEditorMessage( int type, const std::string& message );

    void Undo();
    void Redo();
    void CopySelected();
    void Paste( const LineSegment& mouseray );
    void DeleteSelected();
    void DeleteID(int val);
    void CutSelected();
    void SavePrefab(bool do_resave);
    void SaveSelected();
    void GroupSelected();
    bool ContainsPrefabsRecursively( std::vector<Object*> objects );
    int PrefabSelected();
    void UngroupSelected();
    bool IsSomethingSelected();
    bool IsOneObjectSelected();

    void SendInRabbot();
    void StopRabbot(bool handle_gui = true);

    void SaveEntities(TiXmlNode* root);

    void QueueSaveHistoryState();

    bool CanUndo();
    bool CanRedo();
    void SetViewNavMesh( bool enabled );
    void SetViewCollisionNavMesh(bool enabled);
    bool IsViewingNavMesh();
    bool IsViewingCollisionNavMesh();
    void ToggleImposter();
    void SetImposter(bool set);
    void CPSetColor(const vec3 &color);
    static Object* AddEntityFromDesc( SceneGraph *scenegraph, const EntityDescription& desc, bool level_loading );
    void ApplyScriptParams(const ScriptParamMap& spm, int id);
    void ApplyPalette( const OGPalette &palette, int edited_id );
    OGPalette* GetPalette(int id);
    void ReceiveMessage( const std::string &msg );
    void SetUpSky(const SkyInfo &si);
    void RemoveObject(Object* o, SceneGraph* scenegraph, bool removed_by_socket = false);

    bool WasLastSaveOnCurrentUndoChunk();
    void SetLastSaveOnCurrentUndoChunk();
    void SaveLevel(LevelLoader::SaveLevelType type);

    int CreateObject( const std::string& path);
    int DuplicateObject( const Object* obj );
    int ReplaceObjects( const std::vector<Object*>& objects, const std::string& replacement_path );
    bool IsTypeEnabled( EntityType type );
    void SetTypeEnabled( EntityType type, bool enabled );
    bool IsTypeVisible ( EntityType type );
    void SetTypeVisible( EntityType type, bool enabled );
    Object* GetSelectedCameraObject();
    static void DeselectAll(SceneGraph *scenegraph);
    void ClearUndoHistory();
    void LoadDialogueFile(const std::string &path);
    void UpdateGPUSkinning();
    void CarveAgainstTerrain();
    void ExecuteSaveLevelChanges();
	void AddLightProbes();
	void BakeLightProbes(int pass);
    int LoadEntitiesFromFile(const std::string& filename);
    void ReturnSelected(std::vector<Object*> *selected_objects);
    void RibbonItemClicked(const std::string& item, bool param);
    void SelectAll();
    const StateHistory& state_history() {return state_history_;}

    void ReloadAllPrefabs();
    void ReloadPrefabs(const Path& path);
    bool ReloadPrefab(Object *obj, SceneGraph* scenegraph);

    SceneGraph* GetSceneGraph() { return scenegraph_; }

    Object* control_obj; // editor for curr object controlling the transformations
    ControlEditorInfo control_editor_info;
    EditorTypes::Tool active_tool_;
    SkyEditor* sky_editor_;

    vec4 GetColorHistoryIndex(int index) {return color_history_[index];}

    static const int kColorHistoryLen = 20;
    void AddColorToHistory(vec4 color);

    void PreviewTerrain(const char* heightmap_path, const char* colormap_path, const char* weightmap_path);
    void PreviewTerrainDetailmap(int index, const char* color_path, const char* normal_path, const char* material_path);
    void PreviewTerrainHeightmap(const char* path);
    void PreviewTerrainColormap(const char* path);
    void PreviewTerrainWeightmap(const char* path);

    bool GameplayObjectsEnabled() const;

    const TerrainInfo* GetPreviewTerrainInfo() const;
    bool GetTerrainPreviewMode() const { return terrain_preview_mode; }
	bool CreateObjectFromHost(const std::string& path, const vec3& pos, CommonObjectID host_id);
private:
    void UpdateTransformTool(SceneGraph *scenegraph, EditorTypes::Tool type, const LineSegment &mouseray, const Collision& c, GameCursor* cursor);
    TypeEnable type_enable_;
    TypeEnable type_visible_;
    vec4 color_history_candidate_;

    bool gameplay_objects_enabled_; // The setting is called "gameplay objects" in-game, but the enum value is actually hotspots...

    StateHistory state_history_;
    EntityDescriptionList add_desc_list_;
    Path add_desc_list_source_;
    bool create_as_prefab_;
    SeparatedTransform curr_tool_transform;

    enum {
        LEVEL_PARAM_ID = -1
    };

    void InitializeColorHistory();
    void SaveColorToHistory();
    int color_history_countdown_;
    vec4 color_history_[kColorHistoryLen];

    void UpdateCursor( const LineSegment& mouseray, GameCursor* cursor );
    // internal helper functions
    void DeleteEditors();

    void SetTool( EditorTypes::Tool tool );

    // Control and tool handlers
    void HandleShortcuts( const LineSegment& mouseray );
    void UpdateTools( const LineSegment& mouseray, GameCursor* cursor );
    bool CheckForSelections();
    bool CheckForSelections( const LineSegment& mouseray );
    IMUIContext imui_context;

    void BringAllToCurrentState(int old_state);
	bool HandleScrollSelect(const vec3 &start, const vec3 &end);
    int save_countdown_;

    SceneGraph* scenegraph_;

    EntityDescriptionList copy_desc_list_;

    // Tool structures
    BoxSelector box_selector_;
    EditorTypes::Tool omni_tool_tool_;

    std::vector<Object*> selected; // This is only a member to avoid per-frame memory allocs
    std::vector<Object*> box_objects;

    //Value indicating what point in the undo stack we last saved.
    unsigned last_saved_chunk_global_id;

    void EnterTerrainPreviewMode();
    void ExitTerrainPreviewMode();

    bool terrain_preview_mode;
    TerrainInfo real_terrain_info;
    TerrainObject* terrain_preview;
};

void LoadLevel(bool local);
bool IsBeingMoved(const MapEditor* map_editor, const Object* object);
// Don't move whole code chunk from engine.cpp yet
extern void PlaceLightProbes(SceneGraph* scenegraph, vec3 translation, quaternion rotation, vec3 scale);