1 /* 2 * OpenClonk, http://www.openclonk.org 3 * 4 * Copyright (c) 2006, Armin Burgmeier 5 * Copyright (c) 2010-2016, The OpenClonk Team and contributors 6 * 7 * Distributed under the terms of the ISC license; see accompanying file 8 * "COPYING" for details. 9 * 10 * "Clonk" is a registered trademark of Matthes Bender, used with permission. 11 * See accompanying file "TRADEMARK" for details. 12 * 13 * To redistribute this file separately, substitute the full license texts 14 * for the above references. 15 */ 16 17 #ifndef C4CONSOLEGUI_INC 18 #define C4CONSOLEGUI_INC 19 20 #include "control/C4GameControl.h" 21 #include "game/C4Application.h" 22 #include "player/C4Player.h" 23 24 namespace OpenFileFlags 25 { 26 const DWORD OFN_HIDEREADONLY = 1 << 0; 27 const DWORD OFN_OVERWRITEPROMPT = 1 << 1; 28 const DWORD OFN_FILEMUSTEXIST = 1 << 2; 29 const DWORD OFN_ALLOWMULTISELECT = 1 << 3; 30 31 const DWORD OFN_EXPLORER = 0; // ignored 32 } 33 34 // Separate class containing GUI code for C4Console while C4Console itself only contains functionality 35 class C4ConsoleGUI: public C4Window 36 { 37 public: 38 39 template<class T> class InternalState 40 { 41 protected: 42 typedef class InternalState<T> Super; 43 private: 44 T *owner; 45 public: InternalState(T * owner)46 InternalState(T *owner): owner(owner) {} GetOwner()47 T *GetOwner() {return owner;} 48 }; 49 50 enum InfoTextType 51 { 52 CONSOLE_Cursor, 53 CONSOLE_FrameCounter, 54 CONSOLE_TimeFPS 55 }; 56 57 enum Stage 58 { 59 STAGE_Start, 60 STAGE_Intermediate, 61 STAGE_End, 62 }; 63 64 enum Cursor 65 { 66 CURSOR_Normal, 67 CURSOR_Wait 68 }; 69 70 enum ClientOperation 71 { 72 CO_None, 73 CO_Deactivate, 74 CO_Activate, 75 CO_Kick 76 }; 77 78 class State; 79 80 private: 81 State *state; 82 public: 83 bool Editing; 84 bool fGameOpen; 85 86 C4ConsoleGUI(); 87 ~C4ConsoleGUI() override; 88 89 #ifdef WITH_QT_EDITOR 90 void Execute(); 91 void AddViewport(C4ViewportWindow *cvp); 92 void RemoveViewport(C4ViewportWindow *cvp); 93 void OnObjectSelectionChanged(class C4EditCursorSelection &selection); // selection changed (through other means than creator or object list view) 94 bool CreateNewScenario(StdStrBuf *out_filename, bool *out_host_as_network); 95 void OnStartGame(); 96 void ClearGamePointers(); 97 void EnsureDefinitionListInitialized(); 98 void CloseConsoleWindow(); 99 void ClearPointers(class C4Object *obj); 100 void EditGraphControl(const class C4ControlEditGraph *control); 101 102 // TODO some qt editor stuff is in state and needs to be public 103 // Once other editors are removed, C4ConsoleGUI, C4ConsoleQt and C4ConsoleQtState should be reorganized GetState()104 State *GetState() const { return state; } 105 106 friend class C4ConsoleQtMainWindow; 107 friend class C4ToolsDlg; 108 #else Execute()109 void Execute() { } AddViewport(C4ViewportWindow * cvp)110 void AddViewport(C4ViewportWindow *cvp) { } RemoveViewport(C4ViewportWindow * cvp)111 void RemoveViewport(C4ViewportWindow *cvp) { } OnObjectSelectionChanged(class C4EditCursorSelection & selection)112 void OnObjectSelectionChanged(class C4EditCursorSelection &selection) { } CreateNewScenario(StdStrBuf * out_filename,bool * out_host_as_network)113 bool CreateNewScenario(StdStrBuf *out_filename, bool *out_host_as_network) { return false; } OnStartGame()114 void OnStartGame() { } EnsureDefinitionListInitialized()115 void EnsureDefinitionListInitialized() { } CloseConsoleWindow()116 void CloseConsoleWindow() {} ClearPointers(class C4Object * obj)117 void ClearPointers(class C4Object *obj) {} EditGraphControl(const class C4ControlEditGraph * control)118 void EditGraphControl(const class C4ControlEditGraph *control) {} 119 #endif 120 121 void SetCursor(Cursor cursor); 122 void RecordingEnabled(); 123 void ShowAboutWithCopyright(StdStrBuf ©right); 124 bool UpdateModeCtrls(int iMode); 125 void AddNetMenu(); 126 void ClearNetMenu(); 127 void AddNetMenuItemForPlayer(int32_t client_id, const char *text, C4ConsoleGUI::ClientOperation co); 128 void ClearPlayerMenu(); 129 void SetInputFunctions(std::list<const char*> &functions); 130 131 bool CreateConsoleWindow(C4AbstractApp *application); 132 void DeleteConsoleWindow(); 133 void Out(const char* message); 134 bool ClearLog(); 135 void DisplayInfoText(InfoTextType type, StdStrBuf& text); 136 void SetCaptionToFileName(const char* file_name); 137 bool FileSelect(StdStrBuf *sFilename, const char * szFilter, DWORD dwFlags, bool fSave); 138 void AddMenuItemForPlayer(C4Player *player, StdStrBuf& player_text); 139 void AddKickPlayerMenuItem(C4Player *player, StdStrBuf& player_text, bool enabled); 140 void ClearViewportMenu(); 141 bool Message(const char *message, bool query); 142 EnableControls(bool fEnable)143 void EnableControls(bool fEnable) 144 { 145 if (!Active) return; 146 // disable Editing if no input allowed 147 Editing &= !::Control.NoInput(); 148 DoEnableControls(fEnable); 149 } 150 void DoEnableControls(bool fEnable); 151 UpdateHaltCtrls(bool fHalt)152 bool UpdateHaltCtrls(bool fHalt) 153 { 154 if (!Active) 155 return false; 156 DoUpdateHaltCtrls(fHalt); 157 return true; 158 } 159 bool DoUpdateHaltCtrls(bool fHalt); 160 161 bool PropertyDlgOpen(); 162 void PropertyDlgClose(); 163 void PropertyDlgUpdate(class C4EditCursorSelection &rSelection, bool force_function_update); 164 C4Object * PropertyDlgObject; 165 166 bool ToolsDlgOpen(class C4ToolsDlg *dlg); 167 void ToolsDlgClose(); 168 void ToolsDlgInitMaterialCtrls(class C4ToolsDlg *dlg); 169 void ToolsDlgSelectTexture(C4ToolsDlg *dlg, const char *texture); 170 void ToolsDlgSelectMaterial(C4ToolsDlg *dlg, const char *material); 171 void ToolsDlgSelectBackTexture(C4ToolsDlg *dlg, const char *texture); 172 void ToolsDlgSelectBackMaterial(C4ToolsDlg *dlg, const char *material); 173 174 #ifdef USE_WIN32_WINDOWS 175 void Win32KeepDialogsFloating(HWND hwnd = nullptr); 176 bool Win32DialogMessageHandling(MSG *msg) override; 177 void UpdateMenuText(HMENU hMenu); 178 179 friend INT_PTR CALLBACK PropertyDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); 180 friend INT_PTR CALLBACK ConsoleDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); 181 #endif 182 }; 183 184 #endif 185