Move stuff around

This commit is contained in:
Tamás Bálint Misius 2019-09-20 18:09:51 +02:00
parent a2adff46ce
commit 348ef06a1f
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
14 changed files with 511 additions and 511 deletions

View File

@ -551,7 +551,7 @@ if GetOption('no-install-prompt'):
#Generate list of sources to compile #Generate list of sources to compile
sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/*/*/*.cpp") + Glob("src/*/*/*/*.cpp") + Glob("generated/*.cpp") + Glob("data/*.cpp") sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/*/*/*.cpp") + Glob("generated/*.cpp") + Glob("data/*.cpp")
if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'): if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'):
sources += Glob("src/lua/socket/*.c") + Glob("src/lua/LuaCompat.c") sources += Glob("src/lua/socket/*.c") + Glob("src/lua/LuaCompat.c")

View File

@ -36,7 +36,7 @@
#include "simulation/SimulationData.h" #include "simulation/SimulationData.h"
#include "simulation/ElementDefs.h" #include "simulation/ElementDefs.h"
#include "ElementClasses.h" #include "ElementClasses.h"
#include "gui/options/keyboardbindings/KeyboardBindingsMap.h" #include "gui/keyconfig/KeyconfigMap.h"
#ifdef GetUserName #ifdef GetUserName
# undef GetUserName // dammit windows # undef GetUserName // dammit windows
@ -1403,290 +1403,6 @@ void GameView::BeginStampSelection()
buttonTipShow = 120; buttonTipShow = 120;
} }
void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{
if (introText > 50)
{
introText = 50;
}
if (selectMode != SelectNone)
{
if (selectMode == PlaceSave)
{
switch (key)
{
case SDLK_RIGHT:
c->TranslateSave(ui::Point(1, 0));
return;
case SDLK_LEFT:
c->TranslateSave(ui::Point(-1, 0));
return;
case SDLK_UP:
c->TranslateSave(ui::Point(0, -1));
return;
case SDLK_DOWN:
c->TranslateSave(ui::Point(0, 1));
return;
}
if (scan == SDL_SCANCODE_R && !repeat)
{
if (ctrl && shift)
{
//Vertical flip
c->TransformSave(m2d_new(1,0,0,-1));
}
else if (!ctrl && shift)
{
//Horizontal flip
c->TransformSave(m2d_new(-1,0,0,1));
}
else
{
//Rotate 90deg
c->TransformSave(m2d_new(0,1,-1,0));
}
return;
}
}
}
int32_t functionId = keyboardBindingModel.GetFunctionForBinding(scan, shift, ctrl, alt);
if (repeat)
return;
bool didKeyShortcut = true;
// please see KeyboardBindingsMap.h for mappings
switch(functionId)
{
case KeyboardBindingFunction::TOGGLE_CONSOLE:
{
SDL_StopTextInput();
SDL_StartTextInput();
c->ShowConsole();
break;
}
case KeyboardBindingFunction::PAUSE_SIMULATION: //Space
c->SetPaused();
break;
case KeyboardBindingFunction::UNDO:
if (selectMode != SelectNone && isMouseDown)
break;
if (!isMouseDown)
{
c->HistoryRestore();
}
break;
case KeyboardBindingFunction::REDO:
if (selectMode != SelectNone && isMouseDown)
break;
if (!isMouseDown)
{
c->HistoryForward();
}
break;
case KeyboardBindingFunction::ENABLE_ZOOM:
{
isMouseDown = false;
zoomCursorFixed = false;
c->SetZoomEnabled(true);
break;
}
case KeyboardBindingFunction::PROPERTY_TOOL:
c->SetActiveTool(1, "DEFAULT_UI_PROPERTY");
break;
case KeyboardBindingFunction::TOGGLE_DEBUG_HUD:
SetDebugHUD(!GetDebugHUD());
break;
case KeyboardBindingFunction::RELOAD_SIMULATION:
c->ReloadSim();
break;
case KeyboardBindingFunction::SAVE_AUTHORSHIP_INFO:
if ((Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator
|| Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin) && ctrl)
{
ByteString authorString = Client::Ref().GetAuthorInfo().toStyledString();
new InformationMessage("Save authorship info", authorString.FromUtf8(), true);
}
break;
case KeyboardBindingFunction::OPEN_ELEMENT_SEARCH:
c->OpenElementSearch();
break;
case KeyboardBindingFunction::FIND_MODE:
{
Tool *active = c->GetActiveTool(0);
if (!active->GetIdentifier().Contains("_PT_") || (ren->findingElement == active->GetToolID()))
ren->findingElement = 0;
else
ren->findingElement = active->GetToolID();
break;
}
case KeyboardBindingFunction::FRAME_STEP:
c->FrameStep();
break;
case KeyboardBindingFunction::SHOW_GRAVITY_GRID:
c->ShowGravityGrid();
break;
case KeyboardBindingFunction::DECREASE_GRAVITY_GRID_SIZE:
c->AdjustGridSize(-1);
break;
case KeyboardBindingFunction::INCREASE_GRAVITY_GRID_SIZE:
c->AdjustGridSize(1);
break;
case KeyboardBindingFunction::TOGGLE_INTRO_TEXT:
if(!introText)
introText = 8047;
else
introText = 0;
break;
case KeyboardBindingFunction::TOGGLE_HUD:
showHud = !showHud;
break;
case KeyboardBindingFunction::TOGGLE_DECORATIONS_LAYER:
c->SetDecoration();
break;
case KeyboardBindingFunction::TOGGLE_DECORATION_TOOL:
if (colourPicker->GetParentWindow())
c->SetActiveMenu(lastMenu);
else
{
c->SetDecoration(true);
c->SetPaused(true);
c->SetActiveMenu(SC_DECO);
}
break;
case KeyboardBindingFunction::TOGGLE_AIR_MODE:
c->SwitchAir();
break;
case KeyboardBindingFunction::QUIT:
ui::Engine::Ref().ConfirmExit();
break;
case KeyboardBindingFunction::TOGGLE_HEAT:
c->ToggleAHeat();
break;
case KeyboardBindingFunction::TOGGLE_NEWTONIAN_GRAVITY:
c->ToggleNewtonianGravity();
break;
case KeyboardBindingFunction::RESET_SPARK:
c->ResetSpark();
break;
case KeyboardBindingFunction::RESET_AIR:
c->ResetAir();
break;
case KeyboardBindingFunction::COPY:
{
selectMode = SelectCopy;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)";
buttonTipShow = 120;
break;
}
case KeyboardBindingFunction::CUT:
{
selectMode = SelectCut;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)";
buttonTipShow = 120;
break;
}
case KeyboardBindingFunction::PASTE:
if (c->LoadClipboard())
{
selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
}
break;
case KeyboardBindingFunction::STAMP_TOOL:
{
std::vector<ByteString> stampList = Client::Ref().GetStamps(0, 1);
if (stampList.size())
{
SaveFile *saveFile = Client::Ref().GetStamp(stampList[0]);
if (!saveFile || !saveFile->GetGameSave())
break;
c->LoadStamp(saveFile->GetGameSave());
delete saveFile;
selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
break;
}
}
case KeyboardBindingFunction::OPEN_STAMPS:
{
selectMode = SelectNone;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
c->OpenStamps();
break;
}
case KeyboardBindingFunction::INCREASE_BRUSH_SIZE:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(1, !alt);
else
c->AdjustBrushSize(1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case KeyboardBindingFunction::DECREASE_BRUSH_SIZE:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(-1, !alt);
else
c->AdjustBrushSize(-1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case KeyboardBindingFunction::INSTALL_GAME:
c->Install();
break;
case KeyboardBindingFunction::INVERT_AIR_SIMULATION:
c->InvertAirSim();
break;
case KeyboardBindingFunction::TOGGLE_REPLACE_MODE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
case KeyboardBindingFunction::TOGGLE_SPECIFIC_DELETE_MODE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
default:
didKeyShortcut = false;
}
if (!didKeyShortcut)
{
switch (key)
{
case SDLK_TAB: //Tab
c->ChangeBrush();
break;
case SDLK_INSERT:
if (ctrl)
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
else
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
case SDLK_DELETE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
}
}
if (shift && showDebug && key == '1')
c->LoadRenderPreset(10);
else if (key >= '0' && key <= '9')
{
c->LoadRenderPreset(key-'0');
}
}
void GameView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{
if (repeat)
return;
if (scan == SDL_SCANCODE_Z)
{
if (!zoomCursorFixed && !alt)
c->SetZoomEnabled(false);
return;
}
}
void GameView::OnBlur() void GameView::OnBlur()
{ {
disableAltBehaviour(); disableAltBehaviour();
@ -1894,6 +1610,290 @@ void GameView::DoDraw()
c->Tick(); c->Tick();
} }
void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{
if (introText > 50)
{
introText = 50;
}
if (selectMode != SelectNone)
{
if (selectMode == PlaceSave)
{
switch (key)
{
case SDLK_RIGHT:
c->TranslateSave(ui::Point(1, 0));
return;
case SDLK_LEFT:
c->TranslateSave(ui::Point(-1, 0));
return;
case SDLK_UP:
c->TranslateSave(ui::Point(0, -1));
return;
case SDLK_DOWN:
c->TranslateSave(ui::Point(0, 1));
return;
}
if (scan == SDL_SCANCODE_R && !repeat)
{
if (ctrl && shift)
{
//Vertical flip
c->TransformSave(m2d_new(1,0,0,-1));
}
else if (!ctrl && shift)
{
//Horizontal flip
c->TransformSave(m2d_new(-1,0,0,1));
}
else
{
//Rotate 90deg
c->TransformSave(m2d_new(0,1,-1,0));
}
return;
}
}
}
int32_t functionId = keyboardBindingModel.GetFunctionForBinding(scan, shift, ctrl, alt);
if (repeat)
return;
bool didKeyShortcut = true;
// please see KeyconfigMap.h for mappings
switch(functionId)
{
case KeyconfigFunction::TOGGLE_CONSOLE:
{
SDL_StopTextInput();
SDL_StartTextInput();
c->ShowConsole();
break;
}
case KeyconfigFunction::PAUSE_SIMULATION: //Space
c->SetPaused();
break;
case KeyconfigFunction::UNDO:
if (selectMode != SelectNone && isMouseDown)
break;
if (!isMouseDown)
{
c->HistoryRestore();
}
break;
case KeyconfigFunction::REDO:
if (selectMode != SelectNone && isMouseDown)
break;
if (!isMouseDown)
{
c->HistoryForward();
}
break;
case KeyconfigFunction::ENABLE_ZOOM:
{
isMouseDown = false;
zoomCursorFixed = false;
c->SetZoomEnabled(true);
break;
}
case KeyconfigFunction::PROPERTY_TOOL:
c->SetActiveTool(1, "DEFAULT_UI_PROPERTY");
break;
case KeyconfigFunction::TOGGLE_DEBUG_HUD:
SetDebugHUD(!GetDebugHUD());
break;
case KeyconfigFunction::RELOAD_SIMULATION:
c->ReloadSim();
break;
case KeyconfigFunction::SAVE_AUTHORSHIP_INFO:
if ((Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator
|| Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin) && ctrl)
{
ByteString authorString = Client::Ref().GetAuthorInfo().toStyledString();
new InformationMessage("Save authorship info", authorString.FromUtf8(), true);
}
break;
case KeyconfigFunction::OPEN_ELEMENT_SEARCH:
c->OpenElementSearch();
break;
case KeyconfigFunction::FIND_MODE:
{
Tool *active = c->GetActiveTool(0);
if (!active->GetIdentifier().Contains("_PT_") || (ren->findingElement == active->GetToolID()))
ren->findingElement = 0;
else
ren->findingElement = active->GetToolID();
break;
}
case KeyconfigFunction::FRAME_STEP:
c->FrameStep();
break;
case KeyconfigFunction::SHOW_GRAVITY_GRID:
c->ShowGravityGrid();
break;
case KeyconfigFunction::DECREASE_GRAVITY_GRID_SIZE:
c->AdjustGridSize(-1);
break;
case KeyconfigFunction::INCREASE_GRAVITY_GRID_SIZE:
c->AdjustGridSize(1);
break;
case KeyconfigFunction::TOGGLE_INTRO_TEXT:
if(!introText)
introText = 8047;
else
introText = 0;
break;
case KeyconfigFunction::TOGGLE_HUD:
showHud = !showHud;
break;
case KeyconfigFunction::TOGGLE_DECORATIONS_LAYER:
c->SetDecoration();
break;
case KeyconfigFunction::TOGGLE_DECORATION_TOOL:
if (colourPicker->GetParentWindow())
c->SetActiveMenu(lastMenu);
else
{
c->SetDecoration(true);
c->SetPaused(true);
c->SetActiveMenu(SC_DECO);
}
break;
case KeyconfigFunction::TOGGLE_AIR_MODE:
c->SwitchAir();
break;
case KeyconfigFunction::QUIT:
ui::Engine::Ref().ConfirmExit();
break;
case KeyconfigFunction::TOGGLE_HEAT:
c->ToggleAHeat();
break;
case KeyconfigFunction::TOGGLE_NEWTONIAN_GRAVITY:
c->ToggleNewtonianGravity();
break;
case KeyconfigFunction::RESET_SPARK:
c->ResetSpark();
break;
case KeyconfigFunction::RESET_AIR:
c->ResetAir();
break;
case KeyconfigFunction::COPY:
{
selectMode = SelectCopy;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)";
buttonTipShow = 120;
break;
}
case KeyconfigFunction::CUT:
{
selectMode = SelectCut;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)";
buttonTipShow = 120;
break;
}
case KeyconfigFunction::PASTE:
if (c->LoadClipboard())
{
selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
}
break;
case KeyconfigFunction::STAMP_TOOL:
{
std::vector<ByteString> stampList = Client::Ref().GetStamps(0, 1);
if (stampList.size())
{
SaveFile *saveFile = Client::Ref().GetStamp(stampList[0]);
if (!saveFile || !saveFile->GetGameSave())
break;
c->LoadStamp(saveFile->GetGameSave());
delete saveFile;
selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
break;
}
}
case KeyconfigFunction::OPEN_STAMPS:
{
selectMode = SelectNone;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
c->OpenStamps();
break;
}
case KeyconfigFunction::INCREASE_BRUSH_SIZE:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(1, !alt);
else
c->AdjustBrushSize(1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case KeyconfigFunction::DECREASE_BRUSH_SIZE:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(-1, !alt);
else
c->AdjustBrushSize(-1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case KeyconfigFunction::INSTALL_GAME:
c->Install();
break;
case KeyconfigFunction::INVERT_AIR_SIMULATION:
c->InvertAirSim();
break;
case KeyconfigFunction::TOGGLE_REPLACE_MODE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
case KeyconfigFunction::TOGGLE_SPECIFIC_DELETE_MODE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
default:
didKeyShortcut = false;
}
if (!didKeyShortcut)
{
switch (key)
{
case SDLK_TAB: //Tab
c->ChangeBrush();
break;
case SDLK_INSERT:
if (ctrl)
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
else
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
case SDLK_DELETE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
}
}
if (shift && showDebug && key == '1')
c->LoadRenderPreset(10);
else if (key >= '0' && key <= '9')
{
c->LoadRenderPreset(key-'0');
}
}
void GameView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{
if (repeat)
return;
if (scan == SDL_SCANCODE_Z)
{
if (!zoomCursorFixed && !alt)
c->SetZoomEnabled(false);
return;
}
}
void GameView::NotifyNotificationsChanged(GameModel * sender) void GameView::NotifyNotificationsChanged(GameModel * sender)
{ {
class NotificationButtonAction : public ui::ButtonAction class NotificationButtonAction : public ui::ButtonAction

View File

@ -6,7 +6,7 @@
#include "common/String.h" #include "common/String.h"
#include "gui/interface/Window.h" #include "gui/interface/Window.h"
#include "simulation/Sample.h" #include "simulation/Sample.h"
#include "gui/options/keyboardbindings/KeyboardBindingsModel.h" #include "gui/keyconfig/KeyconfigModel.h"
enum DrawMode enum DrawMode
{ {
@ -115,7 +115,7 @@ private:
SimulationSample sample; SimulationSample sample;
KeyboardBindingsModel keyboardBindingModel; KeyconfigModel keyboardBindingModel;
void updateToolButtonScroll(); void updateToolButtonScroll();

View File

@ -0,0 +1,97 @@
#include "KeyconfigController.h"
#include "KeyconfigView.h"
#include "Controller.h"
#include "client/Client.h"
#include "gui/options/OptionsController.h"
#include "KeyconfigModel.h"
KeyconfigController::KeyconfigController(OptionsController* _parent):
HasExited(false)
{
parent = _parent;
view = new KeyconfigView();
model = new KeyconfigModel();
model->AddObserver(view);
view->AttachController(this);
LoadBindingPrefs();
view->BuildKeyBindingsListView();
}
KeyconfigView* KeyconfigController::GetView()
{
return view;
}
void KeyconfigController::CreateModel(BindingModel _model)
{
model->CreateModel(_model);
}
void KeyconfigController::Save()
{
model->Save();
}
void KeyconfigController::ChangeModel(BindingModel _model)
{
model->RemoveModelByIndex(_model.index);
model->AddModel(_model);
}
void KeyconfigController::Exit()
{
view->CloseActiveWindow();
parent->NotifyKeyBindingsChanged();
HasExited = true;
}
void KeyconfigController::LoadBindingPrefs()
{
model->LoadBindingPrefs();
}
std::vector<BindingModel> KeyconfigController::GetBindingPrefs()
{
return model->GetBindingPrefs();
}
void KeyconfigController::NotifyBindingsChanged()
{
bool hasConflict = model->HasConflictingCombo();
model->NotifyBindingsChanged(hasConflict);
}
void KeyconfigController::ForceHasConflict()
{
view->OnKeyCombinationChanged(true);
}
void KeyconfigController::NotifyKeyReleased()
{
view->OnKeyReleased();
}
void KeyconfigController::PopBindingByFunctionId(int functionId)
{
model->PopBindingByFunctionId(functionId);
}
void KeyconfigController::ResetToDefaults()
{
model->WriteDefaultPrefs(true);
}
bool KeyconfigController::FunctionHasShortcut(int functionId)
{
return model->FunctionHasShortcut(functionId);
}
KeyconfigController::~KeyconfigController()
{
view->CloseActiveWindow();
delete view;
delete callback;
delete model;
}

View File

@ -1,27 +1,27 @@
#ifndef KEYBOARDBINDINGSCONTROLLER_H #ifndef KEYCONFIGSCONTROLLER_H
#define KEYBOARDBINDINGSCONTROLLER_H #define KEYCONFIGSCONTROLLER_H
#include <vector> #include <vector>
class ControllerCallback; class ControllerCallback;
class KeyboardBindingsView; class KeyconfigView;
class GameModel; class GameModel;
class OptionsController; class OptionsController;
class KeyboardBindingsModel; class KeyconfigModel;
struct BindingModel; struct BindingModel;
class KeyboardBindingsController class KeyconfigController
{ {
ControllerCallback * callback; ControllerCallback * callback;
KeyboardBindingsView* view; KeyconfigView* view;
KeyboardBindingsModel* model; KeyconfigModel* model;
OptionsController* parent; OptionsController* parent;
public: public:
bool HasExited; bool HasExited;
KeyboardBindingsController(OptionsController* _parent); KeyconfigController(OptionsController* _parent);
void Exit(); void Exit();
KeyboardBindingsView * GetView(); KeyconfigView * GetView();
virtual ~KeyboardBindingsController(); virtual ~KeyconfigController();
void AddModel(BindingModel model); void AddModel(BindingModel model);
void CreateModel(BindingModel model); void CreateModel(BindingModel model);
void ChangeModel(BindingModel model); void ChangeModel(BindingModel model);
@ -38,4 +38,4 @@ public:
std::vector<BindingModel> GetBindingPrefs(); std::vector<BindingModel> GetBindingPrefs();
}; };
#endif /* KEYBOARDBINDINGSCONTROLLER_H */ #endif /* KEYCONFIGSCONTROLLER_H */

View File

@ -1,22 +1,22 @@
#ifndef KEYBOARDBINDINGSMAP_H #ifndef KEYCONFIGSMAP_H
#define KEYBOARDBINDINGSMAP_H #define KEYCONFIGSMAP_H
#include "common/String.h" #include "common/String.h"
typedef struct KeyboardBindingMap typedef struct KeyconfigMap
{ {
int id; int id;
String description; String description;
int functionId; int functionId;
} KeyboardBindingMap; } KeyconfigMap;
typedef struct DefaultKeyboardBindingMap typedef struct DefaultKeyconfigMap
{ {
ByteString keyCombo; ByteString keyCombo;
int bindingId; // KeyboardBindingMap id int bindingId; // KeyconfigMap id
} DefaultKeyboardBindingMap; } DefaultKeyconfigMap;
static KeyboardBindingMap keyboardBindingFunctionMap[] = static KeyconfigMap keyboardBindingFunctionMap[] =
{ {
{ 0x00, "Reload Simulation", 0 }, { 0x00, "Reload Simulation", 0 },
{ 0x01, "Open Element Search", 1 }, { 0x01, "Open Element Search", 1 },
@ -62,7 +62,7 @@ static KeyboardBindingMap keyboardBindingFunctionMap[] =
{ 0x29, "Toggle Console", 36 } { 0x29, "Toggle Console", 36 }
}; };
enum KeyboardBindingFunction enum KeyconfigFunction
{ {
RELOAD_SIMULATION, RELOAD_SIMULATION,
OPEN_ELEMENT_SEARCH, OPEN_ELEMENT_SEARCH,
@ -103,7 +103,7 @@ enum KeyboardBindingFunction
TOGGLE_CONSOLE TOGGLE_CONSOLE
}; };
static DefaultKeyboardBindingMap defaultKeyboardBindingMapArray[] = static DefaultKeyconfigMap defaultKeyconfigMapArray[] =
{ {
{ "0+62", 0x00 }, { "0+62", 0x00 },
{ "0+8", 0x01 }, { "0+8", 0x01 },

View File

@ -1,16 +1,16 @@
#include "KeyboardBindingsModel.h" #include "KeyconfigModel.h"
#include "client/Client.h" #include "client/Client.h"
#include "SDLCompat.h" #include "SDLCompat.h"
#include "KeyboardBindingsMap.h" #include "KeyconfigMap.h"
#include <algorithm> #include <algorithm>
#include "KeyboardBindingsView.h" #include "KeyconfigView.h"
void KeyboardBindingsModel::WriteDefaultFuncArray(bool force) void KeyconfigModel::WriteDefaultFuncArray(bool force)
{ {
if (force) if (force)
Client::Ref().ClearPref(ByteString(KEYBOARDBINDING_FUNCS_PREF)); Client::Ref().ClearPref(ByteString(KEYCONFIG_FUNCS_PREF));
for (auto defaultBinding : defaultKeyboardBindingMapArray) for (auto defaultBinding : defaultKeyconfigMapArray)
{ {
int functionId; int functionId;
String description; String description;
@ -23,7 +23,7 @@ void KeyboardBindingsModel::WriteDefaultFuncArray(bool force)
} }
} }
ByteString pref = ByteString(KEYBOARDBINDING_FUNCS_PREF) + ByteString(".") + ByteString(functionId); ByteString pref = ByteString(KEYCONFIG_FUNCS_PREF) + ByteString(".") + ByteString(functionId);
bool functionExists = Client::Ref().GetPrefJson(pref, Json::nullValue) != Json::nullValue; bool functionExists = Client::Ref().GetPrefJson(pref, Json::nullValue) != Json::nullValue;
if (!force && functionExists) if (!force && functionExists)
@ -38,19 +38,19 @@ void KeyboardBindingsModel::WriteDefaultFuncArray(bool force)
} }
void KeyboardBindingsModel::WriteDefaultPrefs(bool force) void KeyconfigModel::WriteDefaultPrefs(bool force)
{ {
// Load temporary bindings into memory // Load temporary bindings into memory
// this is so we can add in any new axctions // this is so we can add in any new axctions
// from the KeyboardBindingsMap into our prefs // from the KeyconfigMap into our prefs
LoadBindingPrefs(); LoadBindingPrefs();
if (force) if (force)
Client::Ref().ClearPref(ByteString(KEYBOARDBINDING_PREF)); Client::Ref().ClearPref(ByteString(KEYCONFIG_PREF));
WriteDefaultFuncArray(force); WriteDefaultFuncArray(force);
for (auto defaultBinding : defaultKeyboardBindingMapArray) for (auto defaultBinding : defaultKeyconfigMapArray)
{ {
int functionId; int functionId;
String description; String description;
@ -63,7 +63,7 @@ void KeyboardBindingsModel::WriteDefaultPrefs(bool force)
} }
} }
ByteString pref = ByteString(KEYBOARDBINDING_PREF) + ByteString(".") + defaultBinding.keyCombo; ByteString pref = ByteString(KEYCONFIG_PREF) + ByteString(".") + defaultBinding.keyCombo;
Json::Value prefValue; Json::Value prefValue;
// if we not forcing then check if the function is already set up as a pref // if we not forcing then check if the function is already set up as a pref
@ -95,9 +95,9 @@ void KeyboardBindingsModel::WriteDefaultPrefs(bool force)
LoadBindingPrefs(); LoadBindingPrefs();
} }
void KeyboardBindingsModel::LoadBindingPrefs() void KeyconfigModel::LoadBindingPrefs()
{ {
Json::Value bindings = Client::Ref().GetPrefJson(KEYBOARDBINDING_PREF); Json::Value bindings = Client::Ref().GetPrefJson(KEYCONFIG_PREF);
bindingPrefs.clear(); bindingPrefs.clear();
if (bindings != Json::nullValue) if (bindings != Json::nullValue)
@ -108,7 +108,7 @@ void KeyboardBindingsModel::LoadBindingPrefs()
for (auto& member : keyComboJson) for (auto& member : keyComboJson)
{ {
ByteString keyCombo(member); ByteString keyCombo(member);
ByteString pref = ByteString(KEYBOARDBINDING_PREF) + "." + keyCombo; ByteString pref = ByteString(KEYCONFIG_PREF) + "." + keyCombo;
Json::Value result = Client::Ref().GetPrefJson(pref); Json::Value result = Client::Ref().GetPrefJson(pref);
if (result != Json::nullValue) if (result != Json::nullValue)
@ -129,7 +129,7 @@ void KeyboardBindingsModel::LoadBindingPrefs()
} }
std::pair<int, int> std::pair<int, int>
KeyboardBindingsModel::GetModifierAndScanFromString(ByteString str) KeyconfigModel::GetModifierAndScanFromString(ByteString str)
{ {
int modifier = 0; int modifier = 0;
int scan = 0; int scan = 0;
@ -152,23 +152,23 @@ KeyboardBindingsModel::GetModifierAndScanFromString(ByteString str)
return std::make_pair(modifier, scan); return std::make_pair(modifier, scan);
} }
void KeyboardBindingsModel::TurnOffFunctionShortcut(int functionId) void KeyconfigModel::TurnOffFunctionShortcut(int functionId)
{ {
ByteString pref = ByteString(KEYBOARDBINDING_FUNCS_PREF) + ByteString(".") + ByteString(functionId) ByteString pref = ByteString(KEYCONFIG_FUNCS_PREF) + ByteString(".") + ByteString(functionId)
+ ByteString(".hasShortcut"); + ByteString(".hasShortcut");
Client::Ref().SetPref(pref, false); Client::Ref().SetPref(pref, false);
} }
void KeyboardBindingsModel::TurnOnFunctionShortcut(int functionId) void KeyconfigModel::TurnOnFunctionShortcut(int functionId)
{ {
ByteString pref = ByteString(KEYBOARDBINDING_FUNCS_PREF) + ByteString(".") + ByteString(functionId) ByteString pref = ByteString(KEYCONFIG_FUNCS_PREF) + ByteString(".") + ByteString(functionId)
+ ByteString(".hasShortcut"); + ByteString(".hasShortcut");
Client::Ref().SetPref(pref, true); Client::Ref().SetPref(pref, true);
} }
void KeyboardBindingsModel::RemoveModelByIndex(int index) void KeyconfigModel::RemoveModelByIndex(int index)
{ {
std::vector<BindingModel>::iterator it = bindingPrefs.begin(); std::vector<BindingModel>::iterator it = bindingPrefs.begin();
@ -185,7 +185,7 @@ void KeyboardBindingsModel::RemoveModelByIndex(int index)
} }
} }
void KeyboardBindingsModel::CreateModel(BindingModel model) void KeyconfigModel::CreateModel(BindingModel model)
{ {
// if the function has no shortcut then just turn it on // if the function has no shortcut then just turn it on
if (!FunctionHasShortcut(model.functionId)) if (!FunctionHasShortcut(model.functionId))
@ -202,7 +202,7 @@ void KeyboardBindingsModel::CreateModel(BindingModel model)
bindingPrefs.push_back(model); bindingPrefs.push_back(model);
} }
void KeyboardBindingsModel::AddModel(BindingModel model) void KeyconfigModel::AddModel(BindingModel model)
{ {
bindingPrefs.push_back(model); bindingPrefs.push_back(model);
TurnOnFunctionShortcut(model.functionId); TurnOnFunctionShortcut(model.functionId);
@ -210,23 +210,23 @@ void KeyboardBindingsModel::AddModel(BindingModel model)
NotifyBindingsChanged(hasConflict); NotifyBindingsChanged(hasConflict);
} }
bool KeyboardBindingsModel::FunctionHasShortcut(int functionId) bool KeyconfigModel::FunctionHasShortcut(int functionId)
{ {
ByteString pref = ByteString(KEYBOARDBINDING_FUNCS_PREF) + ByteString(".") + ByteString(functionId) ByteString pref = ByteString(KEYCONFIG_FUNCS_PREF) + ByteString(".") + ByteString(functionId)
+ ByteString(".hasShortcut"); + ByteString(".hasShortcut");
return Client::Ref().GetPrefBool(pref, false); return Client::Ref().GetPrefBool(pref, false);
} }
void KeyboardBindingsModel::Save() void KeyconfigModel::Save()
{ {
Client::Ref().ClearPref(KEYBOARDBINDING_PREF); Client::Ref().ClearPref(KEYCONFIG_PREF);
for (auto& binding : bindingPrefs) for (auto& binding : bindingPrefs)
{ {
ByteString mod(std::to_string(binding.modifier)); ByteString mod(std::to_string(binding.modifier));
ByteString scan(std::to_string(binding.scan)); ByteString scan(std::to_string(binding.scan));
ByteString pref = ByteString(KEYBOARDBINDING_PREF) + ByteString(".") + mod + ByteString("+") + scan; ByteString pref = ByteString(KEYCONFIG_PREF) + ByteString(".") + mod + ByteString("+") + scan;
Json::Value val; Json::Value val;
val["functionId"] = binding.functionId; val["functionId"] = binding.functionId;
@ -237,7 +237,7 @@ void KeyboardBindingsModel::Save()
Client::Ref().WritePrefs(); Client::Ref().WritePrefs();
} }
int KeyboardBindingsModel::GetFunctionForBinding(int scan, bool shift, bool ctrl, bool alt) int KeyconfigModel::GetFunctionForBinding(int scan, bool shift, bool ctrl, bool alt)
{ {
int modifier = 0; int modifier = 0;
@ -272,7 +272,7 @@ int KeyboardBindingsModel::GetFunctionForBinding(int scan, bool shift, bool ctrl
* then we turn off hasShortcut for the associated function * then we turn off hasShortcut for the associated function
* so it renders as *No Shortcut* on the view * so it renders as *No Shortcut* on the view
*/ */
void KeyboardBindingsModel::PopBindingByFunctionId(int functionId) void KeyconfigModel::PopBindingByFunctionId(int functionId)
{ {
std::sort(bindingPrefs.begin(), bindingPrefs.end(), [](BindingModel a, BindingModel b) std::sort(bindingPrefs.begin(), bindingPrefs.end(), [](BindingModel a, BindingModel b)
{ {
@ -306,12 +306,12 @@ void KeyboardBindingsModel::PopBindingByFunctionId(int functionId)
} }
} }
String KeyboardBindingsModel::GetDisplayForModel(BindingModel model) String KeyconfigModel::GetDisplayForModel(BindingModel model)
{ {
return model.description; return model.description;
} }
bool KeyboardBindingsModel::HasConflictingCombo() bool KeyconfigModel::HasConflictingCombo()
{ {
for (auto& binding : bindingPrefs) for (auto& binding : bindingPrefs)
{ {
@ -345,12 +345,12 @@ bool KeyboardBindingsModel::HasConflictingCombo()
return false; return false;
} }
void KeyboardBindingsModel::AddObserver(KeyboardBindingsView* observer) void KeyconfigModel::AddObserver(KeyconfigView* observer)
{ {
observers.push_back(observer); observers.push_back(observer);
} }
void KeyboardBindingsModel::NotifyBindingsChanged(bool hasConflict) void KeyconfigModel::NotifyBindingsChanged(bool hasConflict)
{ {
for (auto& observer : observers) for (auto& observer : observers)
{ {

View File

@ -1,12 +1,12 @@
#ifndef KEYBOARDBINDINGSMODEL_H #ifndef KEYCONFIGSMODEL_H
#define KEYBOARDBINDINGSMODEL_H #define KEYCONFIGSMODEL_H
#include <vector> #include <vector>
#include <utility> #include <utility>
#include "common/String.h" #include "common/String.h"
#define KEYBOARDBINDING_PREF "KeyboardBindings" #define KEYCONFIG_PREF "Keyconfig"
#define KEYBOARDBINDING_FUNCS_PREF "KeyboardBindingFunctions" #define KEYCONFIG_FUNCS_PREF "KeyconfigFunctions"
#define BINDING_MASK 0x07 #define BINDING_MASK 0x07
#define BINDING_CTRL 0x01 #define BINDING_CTRL 0x01
@ -39,12 +39,12 @@ struct BindingModel
} }
}; };
class KeyboardBindingsView; class KeyconfigView;
class KeyboardBindingsModel class KeyconfigModel
{ {
public: public:
KeyboardBindingsModel(){} KeyconfigModel(){}
void WriteDefaultPrefs(bool force = false); // true if user clicks reset to defaults void WriteDefaultPrefs(bool force = false); // true if user clicks reset to defaults
inline std::vector<BindingModel> GetBindingPrefs() const { return bindingPrefs; } inline std::vector<BindingModel> GetBindingPrefs() const { return bindingPrefs; }
@ -54,7 +54,7 @@ public:
void AddModel(BindingModel model); void AddModel(BindingModel model);
void CreateModel(BindingModel model); void CreateModel(BindingModel model);
String GetDisplayForModel(BindingModel model); String GetDisplayForModel(BindingModel model);
void AddObserver(KeyboardBindingsView* observer); void AddObserver(KeyconfigView* observer);
void NotifyBindingsChanged(bool hasConflict); void NotifyBindingsChanged(bool hasConflict);
bool HasConflictingCombo(); bool HasConflictingCombo();
void PopBindingByFunctionId(int functionId); void PopBindingByFunctionId(int functionId);
@ -66,9 +66,9 @@ protected:
void TurnOffFunctionShortcut(int functionId); void TurnOffFunctionShortcut(int functionId);
void TurnOnFunctionShortcut(int functionId); void TurnOnFunctionShortcut(int functionId);
std::vector<KeyboardBindingsView*> observers; std::vector<KeyconfigView*> observers;
std::vector<BindingModel> bindingPrefs; std::vector<BindingModel> bindingPrefs;
std::pair<int, int> GetModifierAndScanFromString(ByteString str); std::pair<int, int> GetModifierAndScanFromString(ByteString str);
}; };
#endif // KEYBOARDBINDINGSMODEL_H #endif // KEYCONFIGSMODEL_H

View File

@ -1,12 +1,12 @@
#include "KeyboardBindingsTextbox.h" #include "KeyconfigTextbox.h"
#include "SDLCompat.h" #include "SDLCompat.h"
#include "gui/interface/Window.h" #include "gui/interface/Window.h"
#include "client/Client.h" #include "client/Client.h"
#include "KeyboardBindingsModel.h" #include "KeyconfigModel.h"
#include "KeyboardBindingsController.h" #include "KeyconfigController.h"
KeyboardBindingsTextbox::KeyboardBindingsTextbox(ui::Point position, ui::Point size) : KeyconfigTextbox::KeyconfigTextbox(ui::Point position, ui::Point size) :
ui::Textbox(position, size) ui::Textbox(position, size)
{ {
// reasonable defaults // reasonable defaults
@ -15,29 +15,29 @@ KeyboardBindingsTextbox::KeyboardBindingsTextbox(ui::Point position, ui::Point s
Appearance.VerticalAlign = ui::Appearance::AlignMiddle; Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
} }
void KeyboardBindingsTextbox::OnMouseClick(int x, int y, unsigned button) void KeyconfigTextbox::OnMouseClick(int x, int y, unsigned button)
{ {
prevKey = GetText(); prevKey = GetText();
SetText(""); SetText("");
c->ForceHasConflict(); c->ForceHasConflict();
} }
void KeyboardBindingsTextbox::AttachController(KeyboardBindingsController* _c) void KeyconfigTextbox::AttachController(KeyconfigController* _c)
{ {
c = _c; c = _c;
} }
void KeyboardBindingsTextbox::SetModel(BindingModel _model) void KeyconfigTextbox::SetModel(BindingModel _model)
{ {
model = _model; model = _model;
} }
void KeyboardBindingsTextbox::SetTextToPrevious() void KeyconfigTextbox::SetTextToPrevious()
{ {
SetText(prevKey); SetText(prevKey);
} }
void KeyboardBindingsTextbox::SetTextFromModifierAndScan(int modifier, int scan) void KeyconfigTextbox::SetTextFromModifierAndScan(int modifier, int scan)
{ {
ByteString modDisplay; ByteString modDisplay;
@ -63,7 +63,7 @@ void KeyboardBindingsTextbox::SetTextFromModifierAndScan(int modifier, int scan)
SetText(keyNameDisplay.FromUtf8()); SetText(keyNameDisplay.FromUtf8());
} }
void KeyboardBindingsTextbox::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) void KeyconfigTextbox::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
ui::Textbox::OnKeyRelease(key, scan, repeat, shift, ctrl, alt); ui::Textbox::OnKeyRelease(key, scan, repeat, shift, ctrl, alt);

View File

@ -1,15 +1,15 @@
#ifndef KEYBOARDBINDINGSTEXTBOX_H #ifndef KEYCONFIGSTEXTBOX_H
#define KEYBOARDBINDINGSTEXTBOX_H #define KEYCONFIGSTEXTBOX_H
#include "gui/interface/Textbox.h" #include "gui/interface/Textbox.h"
#include "KeyboardBindingsModel.h" #include "KeyconfigModel.h"
class KeyboardBindingsController; class KeyconfigController;
class KeyboardBindingsTextbox: public ui::Textbox class KeyconfigTextbox: public ui::Textbox
{ {
public: public:
KeyboardBindingsTextbox(ui::Point position, ui::Point size); KeyconfigTextbox(ui::Point position, ui::Point size);
void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
void OnMouseClick(int x, int y, unsigned button); void OnMouseClick(int x, int y, unsigned button);
@ -20,12 +20,12 @@ public:
void OnTextInput(String text) {} void OnTextInput(String text) {}
void AttachController(KeyboardBindingsController* _c); void AttachController(KeyconfigController* _c);
protected: protected:
String prevKey; String prevKey;
KeyboardBindingsController* c; KeyconfigController* c;
BindingModel model; BindingModel model;
}; };
#endif /* KEYBOARDBINDINGSTEXTBOX_H */ #endif /* KEYCONFIGSTEXTBOX_H */

View File

@ -1,4 +1,4 @@
#include "KeyboardBindingsView.h" #include "KeyconfigView.h"
#include "gui/interface/Button.h" #include "gui/interface/Button.h"
#include "gui/interface/Label.h" #include "gui/interface/Label.h"
@ -8,15 +8,15 @@
#include "gui/interface/ScrollPanel.h" #include "gui/interface/ScrollPanel.h"
#include "gui/Style.h" #include "gui/Style.h"
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
#include "KeyboardBindingsMap.h" #include "KeyconfigMap.h"
#include "KeyboardBindingsTextbox.h" #include "KeyconfigTextbox.h"
#include "KeyboardBindingsModel.h" #include "KeyconfigModel.h"
#include "KeyboardBindingsController.h" #include "KeyconfigController.h"
#include "client/Client.h" #include "client/Client.h"
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
KeyboardBindingsView::KeyboardBindingsView() : KeyconfigView::KeyconfigView() :
ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) { ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) {
ui::Label * tempLabel = new ui::Label(ui::Point(4, 1), ui::Point(Size.X / 2, 22), "Keyboard Bindings"); ui::Label * tempLabel = new ui::Label(ui::Point(4, 1), ui::Point(Size.X / 2, 22), "Keyboard Bindings");
@ -28,8 +28,8 @@ KeyboardBindingsView::KeyboardBindingsView() :
class ResetDefaultsAction: public ui::ButtonAction class ResetDefaultsAction: public ui::ButtonAction
{ {
public: public:
KeyboardBindingsView * v; KeyconfigView * v;
ResetDefaultsAction(KeyboardBindingsView * v_) { v = v_; } ResetDefaultsAction(KeyconfigView * v_) { v = v_; }
void ActionCallback(ui::Button * sender) override void ActionCallback(ui::Button * sender) override
{ {
v->c->ResetToDefaults(); v->c->ResetToDefaults();
@ -52,8 +52,8 @@ KeyboardBindingsView::KeyboardBindingsView() :
class CloseAction: public ui::ButtonAction class CloseAction: public ui::ButtonAction
{ {
public: public:
KeyboardBindingsView * v; KeyconfigView * v;
CloseAction(KeyboardBindingsView * v_) { v = v_; } CloseAction(KeyconfigView * v_) { v = v_; }
void ActionCallback(ui::Button * sender) override void ActionCallback(ui::Button * sender) override
{ {
v->c->Save(); v->c->Save();
@ -70,7 +70,7 @@ KeyboardBindingsView::KeyboardBindingsView() :
AddComponent(scrollPanel); AddComponent(scrollPanel);
} }
void KeyboardBindingsView::ClearScrollPanel() void KeyconfigView::ClearScrollPanel()
{ {
int count = scrollPanel->GetChildCount(); int count = scrollPanel->GetChildCount();
@ -85,7 +85,7 @@ void KeyboardBindingsView::ClearScrollPanel()
textboxes.clear(); textboxes.clear();
} }
void KeyboardBindingsView::BuildKeyBindingsListView() void KeyconfigView::BuildKeyBindingsListView()
{ {
int currentY = 0; int currentY = 0;
float scrollPos = scrollPanel->GetScrollPositionY(); float scrollPos = scrollPanel->GetScrollPositionY();
@ -105,7 +105,7 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
functionLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; functionLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
scrollPanel->AddChild(functionLabel); scrollPanel->AddChild(functionLabel);
KeyboardBindingsTextbox* textbox; KeyconfigTextbox* textbox;
ui::Label* noShortCutLabel; ui::Label* noShortCutLabel;
bool hasBinding = true; bool hasBinding = true;
@ -120,7 +120,7 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
} }
else else
{ {
textbox = new KeyboardBindingsTextbox(ui::Point(functionLabel->Position.X + functionLabel->Size.X + 20, currentY), ui::Point(95, 16)); textbox = new KeyconfigTextbox(ui::Point(functionLabel->Position.X + functionLabel->Size.X + 20, currentY), ui::Point(95, 16));
textbox->SetTextFromModifierAndScan(binding.modifier, binding.scan); textbox->SetTextFromModifierAndScan(binding.modifier, binding.scan);
textbox->SetModel(binding); textbox->SetModel(binding);
textbox->AttachController(c); textbox->AttachController(c);
@ -142,7 +142,7 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
BindingModel nextBinding = *it; BindingModel nextBinding = *it;
if (nextBinding.functionId == binding.functionId) if (nextBinding.functionId == binding.functionId)
{ {
KeyboardBindingsTextbox* tb = new KeyboardBindingsTextbox(ui::Point(functionLabel->Position.X + functionLabel->Size.X + 20, currentY), ui::Point(95, 16)); KeyconfigTextbox* tb = new KeyconfigTextbox(ui::Point(functionLabel->Position.X + functionLabel->Size.X + 20, currentY), ui::Point(95, 16));
if (!nextBinding.isNew) if (!nextBinding.isNew)
tb->SetTextFromModifierAndScan(nextBinding.modifier, nextBinding.scan); tb->SetTextFromModifierAndScan(nextBinding.modifier, nextBinding.scan);
else else
@ -173,11 +173,11 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
class AddBindingAction: public ui::ButtonAction class AddBindingAction: public ui::ButtonAction
{ {
public: public:
KeyboardBindingsView * v; KeyconfigView * v;
int functionId; int functionId;
String desc; String desc;
AddBindingAction(KeyboardBindingsView * v_, int _functionId, String _desc) AddBindingAction(KeyconfigView * v_, int _functionId, String _desc)
{ {
v = v_; v = v_;
functionId = _functionId; functionId = _functionId;
@ -210,10 +210,10 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
class RemoveBindingAction: public ui::ButtonAction class RemoveBindingAction: public ui::ButtonAction
{ {
public: public:
KeyboardBindingsView * v; KeyconfigView * v;
int functionId; int functionId;
RemoveBindingAction(KeyboardBindingsView * v_, int _functionId) RemoveBindingAction(KeyconfigView * v_, int _functionId)
{ {
v = v_; v = v_;
functionId = _functionId; functionId = _functionId;
@ -242,7 +242,7 @@ void KeyboardBindingsView::BuildKeyBindingsListView()
scrollPanel->SetScrollPosition(scrollPos); scrollPanel->SetScrollPosition(scrollPos);
} }
void KeyboardBindingsView::OnKeyReleased() void KeyconfigView::OnKeyReleased()
{ {
for (auto textbox : textboxes) for (auto textbox : textboxes)
{ {
@ -253,24 +253,24 @@ void KeyboardBindingsView::OnKeyReleased()
} }
} }
void KeyboardBindingsView::AttachController(KeyboardBindingsController* c_) void KeyconfigView::AttachController(KeyconfigController* c_)
{ {
c = c_; c = c_;
} }
void KeyboardBindingsView::OnDraw() void KeyconfigView::OnDraw()
{ {
Graphics * g = GetGraphics(); Graphics * g = GetGraphics();
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3); g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
} }
void KeyboardBindingsView::OnTryExit(ExitMethod method) void KeyconfigView::OnTryExit(ExitMethod method)
{ {
c->Exit(); c->Exit();
} }
void KeyboardBindingsView::OnKeyCombinationChanged(bool hasConflict) void KeyconfigView::OnKeyCombinationChanged(bool hasConflict)
{ {
// disable OK button if there's a conflict // disable OK button if there's a conflict
if (hasConflict) if (hasConflict)
@ -285,7 +285,7 @@ void KeyboardBindingsView::OnKeyCombinationChanged(bool hasConflict)
} }
} }
KeyboardBindingsView::~KeyboardBindingsView() KeyconfigView::~KeyconfigView()
{ {
} }

View File

@ -1,5 +1,5 @@
#ifndef KEYBOARDBINDINGSVIEW_H #ifndef KEYCONFIGSVIEW_H
#define KEYBOARDBINDINGSVIEW_H #define KEYCONFIGSVIEW_H
#include "gui/interface/Window.h" #include "gui/interface/Window.h"
@ -10,19 +10,19 @@ namespace ui
class Label; class Label;
} }
class KeyboardBindingsController; class KeyconfigController;
class KeyboardBindingsTextbox; class KeyconfigTextbox;
class KeyboardBindingsView: public ui::Window class KeyconfigView: public ui::Window
{ {
ui::ScrollPanel* scrollPanel; ui::ScrollPanel* scrollPanel;
KeyboardBindingsController* c; KeyconfigController* c;
public: public:
KeyboardBindingsView(); KeyconfigView();
void OnDraw() override; void OnDraw() override;
void OnTryExit(ExitMethod method) override; void OnTryExit(ExitMethod method) override;
void AttachController(KeyboardBindingsController* controller); void AttachController(KeyconfigController* controller);
virtual ~KeyboardBindingsView(); virtual ~KeyconfigView();
void OnKeyCombinationChanged(bool hasConflict); void OnKeyCombinationChanged(bool hasConflict);
void BuildKeyBindingsListView(); void BuildKeyBindingsListView();
void OnKeyReleased(); void OnKeyReleased();
@ -31,7 +31,7 @@ public:
protected: protected:
ui::Button* okayButton; ui::Button* okayButton;
ui::Label* conflictLabel; ui::Label* conflictLabel;
std::vector<KeyboardBindingsTextbox*> textboxes; std::vector<KeyconfigTextbox*> textboxes;
}; };
#endif /* KEYBOARDBINDINGSVIEW_H */ #endif /* KEYCONFIGSVIEW_H */

View File

@ -18,8 +18,8 @@
#include "gui/interface/DropDown.h" #include "gui/interface/DropDown.h"
#include "gui/interface/Engine.h" #include "gui/interface/Engine.h"
#include "gui/interface/Checkbox.h" #include "gui/interface/Checkbox.h"
#include "keyboardbindings/KeyboardBindingsView.h" #include "gui/keyconfig/KeyconfigView.h"
#include "keyboardbindings/KeyboardBindingsController.h" #include "gui/keyconfig/KeyconfigController.h"
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
@ -452,20 +452,20 @@ OptionsView::OptionsView():
scrollPanel->AddChild(tempLabel); scrollPanel->AddChild(tempLabel);
currentY+=20; currentY+=20;
class KeyboardBindingsAction: public ui::ButtonAction class KeyconfigAction: public ui::ButtonAction
{ {
public: public:
KeyboardBindingsAction() { } KeyconfigAction() { }
void ActionCallback(ui::Button * sender) override void ActionCallback(ui::Button * sender) override
{ {
OptionsView* v = (OptionsView*) sender->GetParentWindow(); OptionsView* v = (OptionsView*) sender->GetParentWindow();
KeyboardBindingsController* keyboardBindingsController = new KeyboardBindingsController(v->c); KeyconfigController* keyboardBindingsController = new KeyconfigController(v->c);
ui::Engine::Ref().ShowWindow(keyboardBindingsController->GetView()); ui::Engine::Ref().ShowWindow(keyboardBindingsController->GetView());
} }
}; };
ui::Button * keyboardBindingsButton = new ui::Button(ui::Point(8, currentY), ui::Point(130, 16), "Open Keyboard Bindings"); ui::Button * keyboardBindingsButton = new ui::Button(ui::Point(8, currentY), ui::Point(130, 16), "Open Keyboard Bindings");
keyboardBindingsButton->SetActionCallback(new KeyboardBindingsAction()); keyboardBindingsButton->SetActionCallback(new KeyconfigAction());
scrollPanel->AddChild(keyboardBindingsButton); scrollPanel->AddChild(keyboardBindingsButton);
tempLabel = new ui::Label(ui::Point(keyboardBindingsButton->Position.X+keyboardBindingsButton->Size.X+3, currentY), ui::Point(1, 16), "\bg- Change the keyboard bindings"); tempLabel = new ui::Label(ui::Point(keyboardBindingsButton->Position.X+keyboardBindingsButton->Size.X+3, currentY), ui::Point(1, 16), "\bg- Change the keyboard bindings");

View File

@ -1,97 +0,0 @@
#include "KeyboardBindingsController.h"
#include "KeyboardBindingsView.h"
#include "Controller.h"
#include "client/Client.h"
#include "../OptionsController.h"
#include "KeyboardBindingsModel.h"
KeyboardBindingsController::KeyboardBindingsController(OptionsController* _parent):
HasExited(false)
{
parent = _parent;
view = new KeyboardBindingsView();
model = new KeyboardBindingsModel();
model->AddObserver(view);
view->AttachController(this);
LoadBindingPrefs();
view->BuildKeyBindingsListView();
}
KeyboardBindingsView* KeyboardBindingsController::GetView()
{
return view;
}
void KeyboardBindingsController::CreateModel(BindingModel _model)
{
model->CreateModel(_model);
}
void KeyboardBindingsController::Save()
{
model->Save();
}
void KeyboardBindingsController::ChangeModel(BindingModel _model)
{
model->RemoveModelByIndex(_model.index);
model->AddModel(_model);
}
void KeyboardBindingsController::Exit()
{
view->CloseActiveWindow();
parent->NotifyKeyBindingsChanged();
HasExited = true;
}
void KeyboardBindingsController::LoadBindingPrefs()
{
model->LoadBindingPrefs();
}
std::vector<BindingModel> KeyboardBindingsController::GetBindingPrefs()
{
return model->GetBindingPrefs();
}
void KeyboardBindingsController::NotifyBindingsChanged()
{
bool hasConflict = model->HasConflictingCombo();
model->NotifyBindingsChanged(hasConflict);
}
void KeyboardBindingsController::ForceHasConflict()
{
view->OnKeyCombinationChanged(true);
}
void KeyboardBindingsController::NotifyKeyReleased()
{
view->OnKeyReleased();
}
void KeyboardBindingsController::PopBindingByFunctionId(int functionId)
{
model->PopBindingByFunctionId(functionId);
}
void KeyboardBindingsController::ResetToDefaults()
{
model->WriteDefaultPrefs(true);
}
bool KeyboardBindingsController::FunctionHasShortcut(int functionId)
{
return model->FunctionHasShortcut(functionId);
}
KeyboardBindingsController::~KeyboardBindingsController()
{
view->CloseActiveWindow();
delete view;
delete callback;
delete model;
}