Skip to content

Commit

Permalink
feat(picking): add redo-undo
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Jan 19, 2019
1 parent 50cf423 commit d792b55
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 518 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,8 @@ module CustomEventHandler = {
type dataTuple = Wonderjs.GameObjectPrimitiveType.gameObject;
type return = unit;

let handleSelfLogic = ((store, dispatchFunc), (), uid) => {
StateEditorService.getState()
|> CurrentNodeIdAssetEditorService.clearCurrentNodeId
|> StateEditorService.setState
|> ignore;

StateEditorService.getState()
|> SceneTreeEditorService.setCurrentSceneTreeNode(uid)
|> CurrentSelectSourceEditorService.setCurrentSelectSource(
SceneTreeWidgetService.getWidget(),
)
|> StateEditorService.setState
|> ignore;

StateLogicService.getAndRefreshEngineState();

dispatchFunc(
AppStore.UpdateAction(Update([|SceneTree, Inspector, Project|])),
)
|> ignore;
};
let handleSelfLogic = ((store, dispatchFunc), (), uid) =>
SceneTreeSelectCurrentNodeUtils.select(dispatchFunc, uid);
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let rec _setAllParentsShowChildren = (gameObject, engineState, editorState) =>
switch (GameObjectUtils.getParentGameObject(gameObject, engineState)) {
| None => editorState
| Some(parentGameObject) =>
_setAllParentsShowChildren(
parentGameObject,
engineState,
editorState
|> SceneTreeEditorService.setIsShowChildren(parentGameObject, true),
)
};

let select = (dispatchFunc, uid) => {
StateEditorService.getState()
|> CurrentNodeIdAssetEditorService.clearCurrentNodeId
|> StateEditorService.setState
|> ignore;

StateEditorService.getState()
|> SceneTreeEditorService.setCurrentSceneTreeNode(uid)
|> CurrentSelectSourceEditorService.setCurrentSelectSource(
SceneTreeWidgetService.getWidget(),
)
|> _setAllParentsShowChildren(uid, StateEngineService.unsafeGetState())
|> StateEditorService.setState
|> ignore;

StateLogicService.getAndRefreshEngineStateWhenStop();

dispatchFunc(
AppStore.UpdateAction(Update([|SceneTree, Inspector, Project|])),
)
|> ignore;
};
28 changes: 22 additions & 6 deletions src/core/composable_component/mainEditor/ui/MainEditor.re
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,30 @@ module Method = {
~eventName=EventEditorService.getPickSuccessEventName(),
~handleFunc=
(. ({userData}: EventType.customEvent) as event, engineState) => {
let pickedGameObject =
userData
|> OptionService.unsafeGet
|> InitPickingJobType.userDataToGameObject;

engineState |> StateEngineService.setState |> ignore;

dispatchFunc(
AppStore.UpdateAction(
Update([|UpdateStore.SceneTree, UpdateStore.Inspector|]),
),
)
|> ignore;
switch (
UIHistoryService.getLastStoreInStack(
AllStateData.getHistoryState(),
)
) {
| None =>
SceneTreeSelectCurrentNodeUtils.select(
dispatchFunc,
pickedGameObject,
)
| Some(lastStore) =>
SceneTreeSelectCurrentNodeEventHandler.MakeEventHandler.pushUndoStackWithNoCopyEngineState(
(lastStore, dispatchFunc),
(),
pickedGameObject,
)
};

(StateEngineService.unsafeGetState(), event);
},
Expand Down
14 changes: 4 additions & 10 deletions src/core/utils/engine/job/init/InitEventJobUtils.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
open EventType;

let _loopBodyWhenStop = engineState =>
StateEditorService.getIsRun() ?
engineState : engineState |> DirectorEngineService.loopBody(0.);

let _isTriggerGameViewEvent = () =>
EventEditorService.getEventTarget(StateEditorService.getState()) === Game;

Expand Down Expand Up @@ -62,7 +58,7 @@ module PointEvent = {
);

switch (eventTarget) {
| Scene => _loopBodyWhenStop(engineState)
| Scene => StateLogicService.loopBodyWhenStop(engineState)
| _ => engineState
};
} :
Expand Down Expand Up @@ -370,15 +366,13 @@ module DomEvent = {
(sceneViewEventName, gameViewEventName, event) =>
_isTriggerGameViewEvent() ?
/* _triggerRefreshInspectorEvent |> StateLogicService.getAndSetEngineState; */
_execKeyboardEventHandle(
gameViewEventName,
event,
) :
_execKeyboardEventHandle(gameViewEventName, event) :
_isTriggerSceneViewEvent() ?
{
_execKeyboardEventHandle(sceneViewEventName |> Obj.magic, event);

_loopBodyWhenStop |> StateLogicService.getAndSetEngineState;
StateLogicService.loopBodyWhenStop
|> StateLogicService.getAndSetEngineState;
} :
();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,33 +206,12 @@ let _findPickedOne =
|> _getTopOne(cameraGameObject, engineState);
};

let rec _setAllParentsShowChildren = (gameObject, engineState, editorState) =>
switch (GameObjectUtils.getParentGameObject(gameObject, engineState)) {
| None => editorState
| Some(parentGameObject) =>
_setAllParentsShowChildren(
parentGameObject,
engineState,
editorState
|> SceneTreeEditorService.setIsShowChildren(parentGameObject, true),
)
};

let _selectSceneTreeNode = (gameObject, (editorState, engineState)) => {
let editorState =
SceneTreeEditorService.setCurrentSceneTreeNode(gameObject, editorState)
|> CurrentSelectSourceEditorService.setCurrentSelectSource(
SceneTreeWidgetService.getWidget(),
)
|> _setAllParentsShowChildren(gameObject, engineState);

editorState |> StateEditorService.setState |> ignore;

let _triggerPickSuccessEvent = (gameObject, (editorState, engineState)) => {
let (engineState, _) =
ManageEventEngineService.triggerCustomGlobalEvent(
CreateCustomEventEngineService.create(
EventEditorService.getPickSuccessEventName(),
None,
Some(gameObject),
),
engineState,
);
Expand All @@ -253,7 +232,7 @@ let _handlePicking = (event: EventType.customEvent, engineState) => {
|> _findPickedOne(event, allGameObjectData)
|> OptionService.andThenWithDefault(
gameObject =>
_selectSceneTreeNode(gameObject, (editorState, engineState)),
_triggerPickSuccessEvent(gameObject, (editorState, engineState)),
engineState,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ type ray = {
};

external userDataToPointEvent : EventType.userData => EventType.pointEvent =
"%identity";

external userDataToGameObject :
EventType.userData => Wonderjs.GameObjectPrimitiveType.gameObject =
"%identity";
5 changes: 4 additions & 1 deletion src/service/stateTuple/history/UIHistoryService.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ let storeUIState = (maxStackSize, currentState, historyState) => {
Stack.addFirst(currentState, historyState.uiUndoStack)
|> StackHistoryService.limitStackMaxSize(maxStackSize),
uiRedoStack: Stack.empty(),
};
};

let getLastStoreInStack = historyState =>
historyState.uiUndoStack |> Stack.first;
10 changes: 10 additions & 0 deletions src/service/stateTuple/logic/StateLogicService.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ let getAndRefreshEngineStateWithFunc = handleFunc =>
|> StateEngineService.setState
|> ignore;

let loopBodyWhenStop = engineState =>
StateEditorService.getIsRun() ?
engineState : engineState |> DirectorEngineService.loopBody(0.);

let getAndRefreshEngineStateWhenStop = () =>
StateEngineService.unsafeGetState()
|> loopBodyWhenStop
|> StateEngineService.setState
|> ignore;

let getEditorState = handleFunc => StateEditorService.getState() |> handleFunc;

let getAndSetEditorState = handleFunc =>
Expand Down
Loading

0 comments on commit d792b55

Please sign in to comment.