Skip to content

Commit 2b5577c

Browse files
committed
* Added a hotkey to reset texture offsets.
1 parent c95a59f commit 2b5577c

File tree

7 files changed

+145
-7
lines changed

7 files changed

+145
-7
lines changed

TheForceEngine/TFE_Editor/LevelEditor/editSurface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace LevelEditor
106106
}
107107
if (!sector) { return; }
108108

109-
if (isShortcutPressed(SHORTCUT_COPY_TEXTURE))
109+
if (isShortcutPressed(SHORTCUT_COPY_TEXTURE, 0))
110110
{
111111
const LevelTextureAsset* textureAsset = nullptr;
112112
if (s_view == EDIT_VIEW_2D)
@@ -178,7 +178,7 @@ namespace LevelEditor
178178
edit_clearClipboard();
179179
}
180180
}
181-
else if (isShortcutPressed(SHORTCUT_SET_SIGN) && s_selectedTexture >= 0)
181+
else if (isShortcutPressed(SHORTCUT_SET_SIGN, 0) && s_selectedTexture >= 0)
182182
{
183183
edit_applySignToSelection(s_selectedTexture);
184184
}

TheForceEngine/TFE_Editor/LevelEditor/hotkeys.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ namespace LevelEditor
178178
"LEV_SHORTCUT_TEXOFFSET_LEFT",
179179
"LEV_SHORTCUT_TEXOFFSET_RIGHT",
180180
"LEV_SHORTCUT_TEXOFFSET_PAN",
181+
"LEV_SHORTCUT_TEXOFFSET_RESET",
181182
// Drawing
182183
"LEV_SHORTCUT_REDUCE_CURVE_SEGS",
183184
"LEV_SHORTCUT_INCREASE_CURVE_SEGS",
@@ -244,6 +245,7 @@ namespace LevelEditor
244245
"Move texture offset left", // SHORTCUT_TEXOFFSET_LEFT
245246
"Move texture offset right", // SHORTCUT_TEXOFFSET_RIGHT
246247
"Hold to pan the texture with the mouse", // SHORTCUT_TEXOFFSET_PAN
248+
"Reset the texture offset", // SHORTCUT_TEXOFFSET_RESET
247249
"Reduce curve segments", // SHORTCUT_REDUCE_CURVE_SEGS
248250
"Increase curve segments", // SHORTCUT_INCREASE_CURVE_SEGS
249251
"Reset curve segments to default", // SHORTCUT_RESET_CURVE_SEGS
@@ -461,6 +463,7 @@ namespace LevelEditor
461463
addKeyboardShortcut(SHORTCUT_TEXOFFSET_LEFT, KEY_LEFT);
462464
addKeyboardShortcut(SHORTCUT_TEXOFFSET_RIGHT, KEY_RIGHT);
463465
addKeyboardShortcut(SHORTCUT_TEXOFFSET_PAN, KEY_UNKNOWN, KEYMOD_NONE, MBUTTON_MIDDLE);
466+
addKeyboardShortcut(SHORTCUT_TEXOFFSET_RESET, KEY_T, KEYMOD_ALT);
464467
addKeyboardShortcut(SHORTCUT_REDUCE_CURVE_SEGS, KEY_LEFTBRACKET);
465468
addKeyboardShortcut(SHORTCUT_INCREASE_CURVE_SEGS, KEY_RIGHTBRACKET);
466469
addKeyboardShortcut(SHORTCUT_RESET_CURVE_SEGS, KEY_BACKSLASH);

TheForceEngine/TFE_Editor/LevelEditor/hotkeys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace LevelEditor
4848
SHORTCUT_TEXOFFSET_LEFT,
4949
SHORTCUT_TEXOFFSET_RIGHT,
5050
SHORTCUT_TEXOFFSET_PAN,
51+
SHORTCUT_TEXOFFSET_RESET,
5152
// Drawing
5253
SHORTCUT_REDUCE_CURVE_SEGS,
5354
SHORTCUT_INCREASE_CURVE_SEGS,

TheForceEngine/TFE_Editor/LevelEditor/infoPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ namespace LevelEditor
12891289
EditorSector* sector = nullptr;
12901290
u32 selWallCount = getWallInfoList();
12911291

1292-
const bool insertTexture = s_selectedTexture >= 0 && isShortcutPressed(SHORTCUT_SET_TEXTURE);
1292+
const bool insertTexture = s_selectedTexture >= 0 && isShortcutPressed(SHORTCUT_SET_TEXTURE, 0);
12931293
const bool removeTexture = TFE_Input::mousePressed(MBUTTON_RIGHT);
12941294
const s32 texIndex = insertTexture ? s_selectedTexture : -1;
12951295

TheForceEngine/TFE_Editor/LevelEditor/levelEditor.cpp

Lines changed: 136 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,38 @@ namespace LevelEditor
13281328
}
13291329
}
13301330

1331+
void clearTextureOffset(EditorSector* sector, HitPart part, s32 index)
1332+
{
1333+
if (part == HP_FLOOR)
1334+
{
1335+
sector->floorTex.offset = { 0 };
1336+
}
1337+
else if (part == HP_CEIL)
1338+
{
1339+
sector->ceilTex.offset = { 0 };
1340+
}
1341+
else if (part == HP_MID)
1342+
{
1343+
EditorWall* wall = &sector->walls[index];
1344+
wall->tex[WP_MID].offset = { 0 };
1345+
}
1346+
else if (part == HP_BOT)
1347+
{
1348+
EditorWall* wall = &sector->walls[index];
1349+
wall->tex[WP_BOT].offset = { 0 };
1350+
}
1351+
else if (part == HP_TOP)
1352+
{
1353+
EditorWall* wall = &sector->walls[index];
1354+
wall->tex[WP_TOP].offset = { 0 };
1355+
}
1356+
else if (part == HP_SIGN)
1357+
{
1358+
EditorWall* wall = &sector->walls[index];
1359+
wall->tex[WP_SIGN].offset = { 0 };
1360+
}
1361+
}
1362+
13311363
bool edit_viewportHovered(s32 mx, s32 my)
13321364
{
13331365
return mx >= s_editWinPos.x && mx < s_editWinPos.x + s_editWinSize.x && my >= s_editWinPos.z && my < s_editWinPos.z + s_editWinSize.z;
@@ -3790,6 +3822,54 @@ namespace LevelEditor
37903822
}
37913823
}
37923824
}
3825+
3826+
void edit_resetSelectedTextureOffsets(std::vector<FeatureId>& selected)
3827+
{
3828+
EditorSector* sector = nullptr;
3829+
s32 featureIndex = -1;
3830+
HitPart part = HP_NONE;
3831+
3832+
const s32 count = (s32)selection_getCount();
3833+
if (s_editMode == LEDIT_SECTOR)
3834+
{
3835+
if (!count && selection_hasHovered())
3836+
{
3837+
selection_getSector(SEL_INDEX_HOVERED, sector);
3838+
clearTextureOffset(sector, s_featureTex.part, 0);
3839+
selected.push_back(createFeatureId(sector, 0, s_featureTex.part));
3840+
}
3841+
3842+
// move the floor or ceiling based on hovered.
3843+
for (s32 i = 0; i < count; i++)
3844+
{
3845+
selection_getSector(i, sector);
3846+
clearTextureOffset(sector, s_featureTex.part, 0);
3847+
selected.push_back(createFeatureId(sector, 0, s_featureTex.part));
3848+
}
3849+
}
3850+
else if (s_editMode == LEDIT_WALL)
3851+
{
3852+
if (!count && selection_hasHovered())
3853+
{
3854+
selection_getSurface(SEL_INDEX_HOVERED, sector, featureIndex, &part);
3855+
if (canMoveTexture(part))
3856+
{
3857+
clearTextureOffset(sector, s_featureTex.part, featureIndex);
3858+
selected.push_back(createFeatureId(sector, featureIndex, s_featureTex.part));
3859+
}
3860+
}
3861+
3862+
for (s32 i = 0; i < count; i++)
3863+
{
3864+
selection_getSurface(i, sector, featureIndex, &part);
3865+
if (canMoveTexture(part))
3866+
{
3867+
clearTextureOffset(sector, part, featureIndex);
3868+
selected.push_back(createFeatureId(sector, featureIndex, s_featureTex.part));
3869+
}
3870+
}
3871+
}
3872+
}
37933873

37943874
void mergeFeatureLists(std::vector<FeatureId>& outList, const std::vector<FeatureId>& inList)
37953875
{
@@ -3816,7 +3896,7 @@ namespace LevelEditor
38163896
}
38173897
}
38183898

3819-
void updateTextureMoveFeatures(std::vector<FeatureId>& list, bool clearOnUpdate)
3899+
void updateTextureMoveFeatures(std::vector<FeatureId>& list, bool clearOnUpdate, u16 cmdName)
38203900
{
38213901
s_timeSinceLastUpdate += TFE_System::getDeltaTimeRaw();
38223902
if (list.empty())
@@ -3832,7 +3912,7 @@ namespace LevelEditor
38323912
{
38333913
u16 prevCmd, prevName;
38343914
history_getPrevCmdAndName(prevCmd, prevName);
3835-
if (prevName == LName_MoveTexture)
3915+
if (prevName == cmdName)
38363916
{
38373917
history_removeLast();
38383918
mergeFeatureLists(s_texMoveFeatures, list);
@@ -3850,7 +3930,7 @@ namespace LevelEditor
38503930
if (!s_texMoveFeatures.empty())
38513931
{
38523932
s_timeSinceLastUpdate = 0.0;
3853-
cmd_setTextures(LName_MoveTexture, (s32)s_texMoveFeatures.size(), s_texMoveFeatures.data());
3933+
cmd_setTextures(cmdName, (s32)s_texMoveFeatures.size(), s_texMoveFeatures.data());
38543934
}
38553935
if (clearOnUpdate)
38563936
{
@@ -3868,6 +3948,58 @@ namespace LevelEditor
38683948
std::vector<FeatureId> updatedList;
38693949
bool clearOnUpdate = false;
38703950

3951+
if (isShortcutPressed(SHORTCUT_TEXOFFSET_RESET))
3952+
{
3953+
if (s_view == EDIT_VIEW_2D && s_editMode == LEDIT_SECTOR && canMoveTex && (s_sectorDrawMode == SDM_TEXTURED_CEIL || s_sectorDrawMode == SDM_TEXTURED_FLOOR))
3954+
{
3955+
HitPart part = s_sectorDrawMode == SDM_TEXTURED_CEIL ? HP_CEIL : HP_FLOOR;
3956+
EditorSector* hovered = nullptr;
3957+
if (s_featureTex.sector)
3958+
{
3959+
hovered = s_featureTex.sector;
3960+
s_featureTex.part = part;
3961+
}
3962+
else
3963+
{
3964+
selection_getSector(SEL_INDEX_HOVERED, hovered);
3965+
s_featureTex.sector = hovered;
3966+
s_featureTex.part = part;
3967+
}
3968+
3969+
bool doesItemExist = selection_sector(SA_CHECK_INCLUSION, hovered);
3970+
if (selection_getCount() < 1 || doesItemExist)
3971+
{
3972+
edit_resetSelectedTextureOffsets(updatedList);
3973+
}
3974+
}
3975+
else if (s_view == EDIT_VIEW_3D && s_editMode == LEDIT_WALL && canMoveTex)
3976+
{
3977+
EditorSector* hovered = nullptr;
3978+
HitPart part = HP_NONE;
3979+
s32 featureIndex = -1;
3980+
if (s_featureTex.sector)
3981+
{
3982+
hovered = s_featureTex.sector;
3983+
part = s_featureTex.part;
3984+
featureIndex = s_featureTex.featureIndex;
3985+
}
3986+
else if (selection_getSurface(SEL_INDEX_HOVERED, hovered, featureIndex, &part))
3987+
{
3988+
s_featureTex.sector = hovered;
3989+
s_featureTex.part = part;
3990+
s_featureTex.featureIndex = featureIndex;
3991+
}
3992+
3993+
bool doesItemExist = selection_surface(SA_CHECK_INCLUSION, hovered, featureIndex, part);
3994+
if (selection_getCount() < 1 || doesItemExist)
3995+
{
3996+
edit_resetSelectedTextureOffsets(updatedList);
3997+
}
3998+
}
3999+
updateTextureMoveFeatures(updatedList, true, LName_ClearTextureOffset);
4000+
return;
4001+
}
4002+
38714003
// TODO: Remove code duplication between the 2D and 3D versions.
38724004
if (s_view == EDIT_VIEW_2D && s_editMode == LEDIT_SECTOR && canMoveTex && (s_sectorDrawMode == SDM_TEXTURED_CEIL || s_sectorDrawMode == SDM_TEXTURED_FLOOR))
38734005
{
@@ -4181,7 +4313,7 @@ namespace LevelEditor
41814313
s_featureTex = {};
41824314
}
41834315

4184-
updateTextureMoveFeatures(updatedList, clearOnUpdate);
4316+
updateTextureMoveFeatures(updatedList, clearOnUpdate, LName_MoveTexture);
41854317
}
41864318

41874319
void applyTextureToItem(EditorSector* sector, HitPart part, s32 index, s32 texIndex, Vec2f* offset)

TheForceEngine/TFE_Editor/LevelEditor/levelEditorHistory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace LevelEditor
7878
history_registerName(LName_CreateSectorFromShape, "Create Sector (Shape)");
7979
history_registerName(LName_ExtrudeSectorFromWall, "Extrude Sectors from Wall");
8080
history_registerName(LName_MoveTexture, "Move Texture");
81+
history_registerName(LName_ClearTextureOffset, "Reset Texture Offsets");
8182
history_registerName(LName_SetTexture, "Set Texture");
8283
history_registerName(LName_CopyTexture, "Copy Texture");
8384
history_registerName(LName_ClearTexture, "Clear Texture");

TheForceEngine/TFE_Editor/LevelEditor/levelEditorHistory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace LevelEditor
2424
LName_CreateSectorFromShape,
2525
LName_ExtrudeSectorFromWall,
2626
LName_MoveTexture,
27+
LName_ClearTextureOffset,
2728
LName_SetTexture,
2829
LName_CopyTexture,
2930
LName_ClearTexture,

0 commit comments

Comments
 (0)