This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/gui/game/GameView.h
Ian Bastos bf0cc9ba5f
Implement keyboard hotkey bindings (heavily squashed)
- add keyboard bindings button to options
 - hooked keyboard binding panel to button
 - WIP bindings drawn in activity
 - keyboard binding keys finally appear
 - keyboard binding input widget
 - reserved keys logic working
 - removed debug logs
 - pref saved on key release
 - more reserved keys
 - fixed memory bad alloc error
 - modifier bindings
 - scroll panel for bindings view
 - added sdl id to bindings
 - cache sdl scan id into prefs
 - function ids are getting picked up
 - more keyboard mappings
 - more key bindings + reserved keys
 - keyboard bindings working
 - write keyboard bindings pref on load
 - sync new functions to prefs
 - final touches
 - Keep those include trees flat (see 0179cefc)
 - Fix tabs
 - WIP - many to one binding
 - WriteDefaultPrefs is now instance method
 - model add, remove and save methods
 - clear prefs before saving
 - added method for checking binding conflict
 - notify view on key combo change
 - route binding notification to gameview
 - view foundations for overhaul
 - fixed memory issue + has conflicting key issue
 - fixed prefs not being cleared before save
 - override text input to do nothing
 - fixed many complications due to duplicated hotkeys
 - missing index on new model caused problems
 - WIP - view adaptation
 - WIP - add and remove button layout
 - more patches
 - fixed empty textboxes problem
 - WIP - frontend overhaul
 - fixed ordering issue
 - binding removal - wip
 - function store to hold no shortcut data
 - reset to defaults button added
 - add from no shortcut works
 - error message on conflict
 - better summary for PopBindingByFunctionId
 - keyboard bindings hooked to gameview keypress
 - do not return correcty function id if no shortcut
 - flatten include trees
 - remove debug comment
 - spaces to tabs
2019-09-17 19:44:37 +02:00

222 lines
6.3 KiB
C++

#ifndef GAMEVIEW_H
#define GAMEVIEW_H
#include <vector>
#include <deque>
#include "common/String.h"
#include "gui/interface/Window.h"
#include "simulation/Sample.h"
#include "gui/options/keyboardbindings/KeyboardBindingsModel.h"
enum DrawMode
{
DrawPoints, DrawLine, DrawRect, DrawFill
};
enum SelectMode
{
SelectNone, SelectStamp, SelectCopy, SelectCut, PlaceSave
};
namespace ui
{
class Button;
class Slider;
class Textbox;
}
class Renderer;
class VideoBuffer;
class ToolButton;
class GameController;
class Brush;
class GameModel;
class GameView: public ui::Window
{
private:
bool isMouseDown;
bool skipDraw;
bool zoomEnabled;
bool zoomCursorFixed;
bool mouseInZoom;
bool drawSnap;
bool shiftBehaviour;
bool ctrlBehaviour;
bool altBehaviour;
bool showHud;
bool showDebug;
int delayedActiveMenu;
bool wallBrush;
bool toolBrush;
bool decoBrush;
bool windTool;
int toolIndex;
int currentSaveType;
int lastMenu;
int toolTipPresence;
String toolTip;
bool isToolTipFadingIn;
ui::Point toolTipPosition;
int infoTipPresence;
String infoTip;
int buttonTipShow;
String buttonTip;
bool isButtonTipFadingIn;
int introText;
String introTextMessage;
bool doScreenshot;
int screenshotIndex;
bool recording;
int recordingFolder;
ui::Point currentPoint, lastPoint;
GameController * c;
Renderer * ren;
Brush * activeBrush;
//UI Elements
std::vector<ui::Button*> quickOptionButtons;
std::vector<ui::Button*> menuButtons;
std::vector<ToolButton*> toolButtons;
std::vector<ui::Component*> notificationComponents;
std::deque<std::pair<String, int> > logEntries;
ui::Button * scrollBar;
ui::Button * searchButton;
ui::Button * reloadButton;
ui::Button * saveSimulationButton;
bool saveSimulationButtonEnabled;
bool saveReuploadAllowed;
ui::Button * downVoteButton;
ui::Button * upVoteButton;
ui::Button * tagSimulationButton;
ui::Button * clearSimButton;
ui::Button * loginButton;
ui::Button * simulationOptionButton;
ui::Button * displayModeButton;
ui::Button * pauseButton;
ui::Button * colourPicker;
std::vector<ToolButton*> colourPresets;
DrawMode drawMode;
ui::Point drawPoint1;
ui::Point drawPoint2;
SelectMode selectMode;
ui::Point selectPoint1;
ui::Point selectPoint2;
ui::Point currentMouse;
ui::Point mousePosition;
VideoBuffer * placeSaveThumb;
ui::Point placeSaveOffset;
SimulationSample sample;
KeyboardBindingsModel keyboardBindingModel;
void updateToolButtonScroll();
void SetSaveButtonTooltips();
void screenshot();
void enableShiftBehaviour();
void disableShiftBehaviour();
void enableCtrlBehaviour();
void disableCtrlBehaviour();
void enableAltBehaviour();
void disableAltBehaviour();
void UpdateDrawMode();
void UpdateToolStrength();
public:
GameView();
virtual ~GameView();
//Breaks MVC, but any other way is going to be more of a mess.
ui::Point GetMousePosition();
void SetSample(SimulationSample sample);
void SetHudEnable(bool hudState);
bool GetHudEnable();
void SetDebugHUD(bool mode);
bool GetDebugHUD();
bool GetPlacingSave();
bool GetPlacingZoom();
void SetActiveMenuDelayed(int activeMenu) { delayedActiveMenu = activeMenu; }
bool CtrlBehaviour(){ return ctrlBehaviour; }
bool ShiftBehaviour(){ return shiftBehaviour; }
bool AltBehaviour(){ return altBehaviour; }
SelectMode GetSelectMode() { return selectMode; }
void BeginStampSelection();
ui::Point GetPlaceSaveOffset() { return placeSaveOffset; }
void SetPlaceSaveOffset(ui::Point offset) { placeSaveOffset = offset; }
int Record(bool record);
//all of these are only here for one debug lines
bool GetMouseDown() { return isMouseDown; }
bool GetDrawingLine() { return drawMode == DrawLine && isMouseDown; }
bool GetDrawSnap() { return drawSnap; }
ui::Point GetLineStartCoords() { return drawPoint1; }
ui::Point GetLineFinishCoords() { return currentMouse; }
ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
void AttachController(GameController * _c){ c = _c; }
void NotifyRendererChanged(GameModel * sender);
void NotifySimulationChanged(GameModel * sender);
void NotifyPausedChanged(GameModel * sender);
void NotifySaveChanged(GameModel * sender);
void NotifyBrushChanged(GameModel * sender);
void NotifyMenuListChanged(GameModel * sender);
void NotifyToolListChanged(GameModel * sender);
void NotifyActiveToolsChanged(GameModel * sender);
void NotifyUserChanged(GameModel * sender);
void NotifyZoomChanged(GameModel * sender);
void NotifyColourSelectorVisibilityChanged(GameModel * sender);
void NotifyColourSelectorColourChanged(GameModel * sender);
void NotifyColourPresetsChanged(GameModel * sender);
void NotifyColourActivePresetChanged(GameModel * sender);
void NotifyPlaceSaveChanged(GameModel * sender);
void NotifyNotificationsChanged(GameModel * sender);
void NotifyLogChanged(GameModel * sender, String entry);
void NotifyToolTipChanged(GameModel * sender);
void NotifyInfoTipChanged(GameModel * sender);
void NotifyQuickOptionsChanged(GameModel * sender);
void NotifyLastToolChanged(GameModel * sender);
void NotifyKeyBindingsChanged(GameModel * sender);
void ToolTip(ui::Point senderPosition, String toolTip) override;
void OnMouseMove(int x, int y, int dx, int dy) override;
void OnMouseDown(int x, int y, unsigned button) override;
void OnMouseUp(int x, int y, unsigned button) override;
void OnMouseWheel(int x, int y, int d) override;
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
void OnTick(float dt) override;
void OnDraw() override;
void OnBlur() override;
void OnFileDrop(ByteString filename) override;
//Top-level handlers, for Lua interface
void DoExit() override;
void DoDraw() override;
void DoMouseMove(int x, int y, int dx, int dy) override;
void DoMouseDown(int x, int y, unsigned button) override;
void DoMouseUp(int x, int y, unsigned button) override;
void DoMouseWheel(int x, int y, int d) override;
void DoTextInput(String text) override;
void DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
void DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
class MenuAction;
class ToolAction;
class OptionAction;
class OptionListener;
};
#endif // GAMEVIEW_H