1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-03 03:23:33 +02:00
Commit Graph

81 Commits

Author SHA1 Message Date
AllyTally
bd3b9cac31 Add finalstretch support for custom levels 2023-10-19 00:06:10 -03:00
Dav999
d741b3aa27 Fix double return when pressing Esc in editor font menu
The line that checked if the current menu is the font menu ended up
below the code that returned a menu, so this was an easy fix.

Closes #1017.
2023-09-13 23:58:34 -07:00
AllyTally
3f69b64a09 Fix yellow lab autotiling
A few autotile entries were missing.
2023-09-09 23:04:47 -07:00
AllyTally
5b2fbeb6b4 Fix gravity line edgeguides 2023-09-09 16:34:26 -07:00
AllyTally
6549dc0113 Change lab autotiling 2023-08-25 09:55:17 -07:00
AllyTally
a537492d9c Remove NO_EDITOR/NO_CUSTOM_LEVELS, disable editor on Steam Deck
This commit removes the `NO_EDITOR` and `NO_CUSTOM_LEVELS` defines,
which cleans up the code a lot, and they weren't really needed anyways.

This commit also disables the editor on the Steam Deck, and adds a
program argument to re-enable the editor, `-enable-editor`.
2023-08-25 09:50:27 -07:00
AllyTally
6952c58878 Fix texture cache missing in certain situations after resizing the window 2023-08-23 09:23:10 -07:00
Misa
8e3e29a14c Generalize stretch mode mouse scaling fix
This puts the code to fix mouse coordinates in stretch mode directly
inside KeyPoll::Poll, preventing the need for any other instances of
mouse coordinate usage to copy-paste code.
2023-08-17 19:57:54 -07:00
AllyTally
e36c2764fb Add separate tilecol max for direct mode
This commit readds the ability to select the rainbow BG in lab tileset
in direct mode.
2023-06-06 21:46:19 -07:00
AllyTally
17e0d6c330 Don't trigger UB with autotile type none 2023-06-06 21:46:19 -07:00
AllyTally
a37cb4aa5f Rewrite autotiling completely
Autotiling was a mess of functions and if chains and switch statements.
This commit makes autotiling better by assigning each direction to one
bit in a byte, giving each different combination its own value. This
value is then fed into a lookup table to give fine control on which
tiles get placed where.

The lab tileset can now use the single tiles which were before unused
in the autotiler, and the warp zone's background tool now places the
fill used in the main game.
2023-06-06 21:46:19 -07:00
Misa
4058975ce9 Use enums for sound effects
This adds an anonymous enum for sound effects and replaces all calls to
music.playef that use integer literals.

This is not a named enum (that can be used for strict typechecking)
because sound effect IDs are essentially part of the API of the game -
many custom levels use these numbers. This is just to make the source
code more readable without needing a comment to denote what number is
what sound.
2023-06-05 17:57:23 -07:00
Misa
cdeca65be7 Use enums for music tracks
This adds an anonymous enum for music tracks and replaces all calls to
music.play and music.niceplay that use integer literals. Additionally,
this is also done for integer literals for cl.levmusic (except 0) and
music.currentsong where appropriate, but _not_ the music areamap because
that would not make it look very aesthetically pleasing in the code.

This is not a named enum (that can be used for strict typechecking)
because music track IDs are essentially part of the API of the game -
almost every custom level uses these numbers. This is just to make the
source code more readable without needing a comment to denote what
number is what track.
2023-06-05 17:57:23 -07:00
Misa
27aa10a18c Fix regression: Editing script disables mute buttons
This is quite a simple bug: If you edit a script, then close it, you
will no longer be able to use the mute buttons (N and M).

The problem here is that in 2.3, key.disabletextentry() was called when
closing a script. However, #944 removed the call. Therefore, a
regression.
2023-05-15 18:25:43 -07:00
AllyTally
f3cf771cc8 CTRL+, and CTRL+. to modify platv
`platv` is a room property that controls platform speed, and it has
always worked (other than some weird storage issues due to a bug).
However, the editor has no way to edit it currently, so people had to
resort to editing the level file by hand, or with a third-party tool.
This commit simply adds an easy way to modify platform speed.
2023-04-02 23:48:09 -07:00
AllyTally
d328be2a03 Add fill bucket subtool
VED has a fill bucket subtool for tiles and backgrounds, which is
really useful when creating rooms. This commit adds a fill bucket as
well, with an adaptive tool highlight, unlike VED.
2023-04-02 23:48:09 -07:00
Misa
71dbe95dcb Separate CustomEntity global positions internally
This makes it so that `CustomEntity`s, at least internally, do not use
global tile position. Instead, they will use room-x and room-y
coordinates, which will be separate from their x- and y- positions.

This makes it much easier to deal with `CustomEntity`s, because you
don't have to divide and modulo everywhere to use them.

Since editorclass::add_entity and editorclass::get_entity_at expect
global tile position in their arguments, I've added room-x and room-y
arguments to these functions too.

Of course, due to compatibility reasons, the XML files will still have
to use global tile position. For the same reason, warp token
destinations are still using global tile position too.
2023-03-29 13:49:08 -07:00
AllyTally
0961084ff9 Fix missing leftbutton check 2023-03-24 11:13:16 -07:00
Ally
0edbf6398a Add suggestions from style pass
Co-authored-by: Misa Elizabeth Kai <infoteddy@infoteddy.info>
2023-03-21 15:41:49 -07:00
AllyTally
234776bbec Fix macOS build errors/warnings 2023-03-21 15:41:49 -07:00
AllyTally
045ce3a0fc Allow placing warp token destination in walls
Staying consistent with how entities can now be placed in walls, the
warp token destination should follow this as well.
2023-03-21 15:41:49 -07:00
AllyTally
08084e5a97 Add edge-guides for horizontal gravity lines
These visualize the horizontal gravity line kludge for rooms beside
eachother. When you enter another room, gravity lines which look like
they're connected between the rooms try to have the same activated
state.

Basically, if you're in room (1,4) and you go into (2,4), if a
gravity line in (1,4) is activated (gray, on cooldown) and it's
touching the gravity line in (2,4), that gravity line will also be
activated.
2023-03-21 15:41:49 -07:00
AllyTally
d152730510 Add interpolation to tile tools
This uses DDA (https://w.wiki/6RSQ) to draw a line between the previous
frame's mouse position, and the current frame's mouse position. This
means that there will no longer be gaps in lines of tiles if you move
your mouse fast enough (which is actually rather slow, so it gets
annoying quickly).

The editor's timestep is no longer hardcoded to 24, as I assume that
was only done so there would be less gaps in lines of tiles drawn.
With interpolation, that is no longer an issue, so I've removed the
editor's special case for the timestep.
2023-03-21 15:41:49 -07:00
AllyTally
6cae666c76 Clean up scripts in the editor
Scripts used a weird "hook" system, where script names were extracted
into their own list. This was completely unneeded, so it has been
replaced with using the script.customscripts vector directly.

The script editor has been cleaned up, so the cursor's Y position is
relative to the entire script, rather than what's just displaying on
the screen currently. This simplifies a lot of code, and I don't know
why it was done the other way in the first place.

The script selector and script editor cursors have been sped up, since
both lists can be massive, and waiting 6 frames per line is extremely
slow and boring. This is still slow and boring, but we don't have
proper input repetition yet.
2023-03-21 15:41:49 -07:00
AllyTally
7ac405c831 Move everything to the editor state system
This commit moves everything left out of the previous commit to the
state system. This means a bunch of new functions were added as well,
to avoid the code in each function becoming too huge. A lot of cleanup
was done as well, simplifying logic, merging duplicated code, etc.

This commit does NOT touch "script hooks", script editor logic and
autotiling, as those seem to be their own separate beasts.
2023-03-21 15:41:49 -07:00
AllyTally
7b5ef40926 Fix gravity/warp lines being modified during draw
While warp lines were being drawn, they also got resized to
automatically fit between collision. In renderfixed, gravity lines are
resized the same way. Doing logic while drawing is very poor practice,
so resizing of these has been moved into logic, and merged together.

Aside from some more cleanup, this commit also removes the very poorly
done right click emulation, when you hold CTRL and click. It never
worked well in the past, and even requires a right click to use, so
there's not really any point to keeping it around.
2023-03-21 15:41:49 -07:00
AllyTally
84c6d44c52 Clean code for direct mode drawer
The drawer could definitely be improved further, however I cleaned up a
little bit of the code duplication. I'll have to take a closer look
some other time, but I'm pretty sure that the duplicated code at the
bottom can be removed with a few tweaks, but I'll do that carefully
in a different commit.
2023-03-21 15:41:49 -07:00
AllyTally
34cc15505b Cleanup tools & main rendering
Tools were a mess, spread all over the code with hundreds of `else-if`
statements. Instead of magic numbers denoting tools, an enum has been
created, and logic has been extracted into simple switch/cases, shared
logic being deduplicated.

The base of a state system for the editor has been created as well,
laying a good path for further organization improvements. Because of
this, the entire editor no longer gets drawn underneath the menus,
except for a few pieces which I haven't extracted yet. Either way,
this should be good for performance, if that was a concern.
2023-03-21 15:41:49 -07:00
Misa
54990638fd Persist windowed mode size through fullscreen mode
Previously, the game would not store the size of the window itself, and
would always call SDL_GetRendererOutputSize() (via
Screen::GetWindowSize()) to figure out the size of the window. The only
problem is, this would return the size of the whole monitor if the game
was in fullscreen mode. And the only place where the original windowed
mode size was stored would be in SDL itself, but that wouldn't persist
after the game was closed.

So, if you exited the game while in fullscreen mode, then your window
size would get set to the size of your monitor (1920 by 1080 in my
case). Then when you opened the game and toggled fullscreen off, it
would go back to the default window size, which is 640 by 480.

This is made worse, however, if you were in forced fullscreen mode when
you previously exited the game in windowed mode. In that case, the game
saves the size of 1920 by 1080, but doesn't save that you were in
fullscreen mode, so opening the game not in forced fullscreen mode would
result in you having a 1920 by 1080 window, but in windowed mode.
Meaning that not even fullscreening and unfullscreening would put the
game window back to normal size.

The solution, of course, is to just store the window size ourselves,
like any other screen setting, and only use GetWindowSize() if needed.
And just to make things clear, I've also renamed the GetWindowSize()
function to GetScreenSize(), because if it was named "window" it could
lead one to think that it would always return the size of the screen in
windowed mode, when in fact it returns the size of the screen whatever
mode it is in - fullscreen size if in fullscreen mode and window size if
in windowed mode.

And doing this also fixes the FIXME above Screen::isForcedFullscreen().
2023-03-20 20:59:37 -07:00
Dav999-v
d112dee72c Change font::len text argument from std::string to const char*
See the previous two commits, a lot of the time we don't need
std::string objects to be passed to these functions because we already
have C strings.

   Commit 1/3: font::print_wrap
   Commit 2/3: font::print
-> Commit 3/3: font::len
2023-03-04 16:10:17 -08:00
Dav999-v
264b6474be Change font::print_wrap text argument from std::string to const char*
We no longer need to pass a std::string object to the print and len
functions - in fact, we often only have a C string that we want to
print or get the visual width of (that C string most often comes from
loc::gettext), and it's a bit wasteful to wrap it in a new std::string
object on every print/len call.

This does mean adding a few more .c_str()s, but there's not many places
where a std::string is being passed to these functions, and we already
use .c_str() sometimes.

-> Commit 1/3: font::print_wrap
   Commit 2/3: font::print
   Commit 3/3: font::len
2023-03-04 16:10:17 -08:00
Dav999-v
c5a48776c9 Replace utfcpp by UTF8.h in Editor.cpp 2023-02-27 23:00:41 -08:00
Misa
2ac85e6929 Fix editor selection box not showing up
Whoops.

Also outlined the text for page 2 too.
2023-02-19 12:31:58 -08:00
Misa
6e6cf1bfc3 Draw text outline on editor hotkeys
This makes them stand out more.

The border around the tool has also been moved to be drawn first.
Otherwise, it would be drawn on top of the outline of the text, which
would look bad.
2023-02-19 12:12:02 -08:00
Dav999-v
d1f6c1adf2 Replace "by" for level authors with happy face
"by {author}" is a string that will cause a lot of localization-related
problems, which then become much worse when different languages and
levels can also need different fonts:

- If the author name is set to something in English instead of a name,
  then it'll come out a bit weird if your VVVVVV is set to a different
  language: "de various people", "por various people", etc. It's the
  same problem with Discord bots completing "playing" or "watching" in
  their statuses.

- Translators can't always fit "by" in two letters, and level creators
  have understandably always assumed, and will continue to assume, that
  "by" is two letters. So if you have your VVVVVV set to a language that
  translates "by" as something long, then:
  | by Various People and Others |
  ...may suddenly show up as something like:
  |thorer Various People and Othe|

- "by" and author may need mutually incompatible fonts. For example, a
  Japanese level in a Korean VVVVVV needs to be displayed with "by" in
  Korean characters and the author name with Japanese characters, which
  would need some very special code since languages may want to add
  text both before and after the name.

- It's very possible that some languages can't translate "by" without
  knowing the gender of the name, and I know some languages even
  inflect names in really interesting ways (adding and even replacing
  letters in first names, surnames, and anything in between, depending
  on gender and what else is in the sentence).

So to solve all of this, the "by" is now replaced by a 10x10 face from
sprites.png, like a :viridian: emote. See it as a kind of avatar next
to a username, to clarify and assert that this line is for the author's
name. It should be a fairly obvious/recognizable icon, it fixes all the
above problems, and it's a bonus that we now have more happy faces in
VVVVVV.
2023-02-13 23:27:00 -08:00
Dav999-v
ed7379c41b Position CJK room name correctly in editor 2023-02-13 23:27:00 -08:00
Dav999-v
9747843c18 Add menu for selecting the level font
By default, when you open the level editor to start a new level, the
level font will now match your VVVVVV language; so if you're, say,
Japanese, then you can make Japanese levels from the get-go. If you
want to make levels for a different target audience, you can change the
font via a new menu (map settings > change description > change font).
The game will remember this choice and it will become the new initial
level font.
2023-02-13 23:27:00 -08:00
Dav999-v
25feb9dbb5 Make wordwrapping functions take font arguments
They need to know how wide the text is going to be in a particular
font, so font::string_wordwrap and font::string_wordwrap_balanced now
take a flags argument like all the printing and dimensions-getting
functions. next_wrap and next_wrap_s take a Font* now, they're internal
to Font.cpp so they can take a Font and avoid double flag-parsing. But
if any non-Font.cpp code needs next_wrap/next_wrap_s in the future, I'd
just make a public wrapper that takes a uint32_t flags and passes the
Font* to the internal functions.
2023-02-13 23:27:00 -08:00
Dav999-v
0eaceed0a2 Completely remove Graphics::PrintWrap
All print calls are font:: ones now and all the old Graphics:: print
functions have been removed, the migration is complete!
2023-02-13 23:27:00 -08:00
Dav999-v
7ecff42e0e Completely remove Graphics::Print, make many CJK positioning fixes
Only Graphics::PrintWrap is left of the old print functions!
2023-02-13 23:27:00 -08:00
Dav999-v
8d5e3b1a8a Improve level metadata display and font handling
- If the level font is higher than 10 pixels, the third description
  line (Desc3) is disabled and unavailable. CJK languages require less
  characters to convey the same message (140 characters caused people
  to cram tweets in all languages except CJK) and this gives us enough
  room in the levels list without having to cram the metadata even more
  than it already was or showing less levels per page.
- The "Untitled Level" and "by Unknown" now selectively show up in the
  interface font instead of the level font.
2023-02-13 23:27:00 -08:00
Dav999-v
d2461c90ce Completely remove Graphics::bigprint
The last two deprecated functions are:
- Graphics::Print
- Graphics::PrintWrap

These are used a lot, but they're relatively easy to replace, since the
only flag I probably have to immediately worry about is PR_CEN. I do
often need to add PR_FONT_* flags but I don't need to add any
PR_2X/PR_3X/PR_4X anymore.
2023-02-13 23:27:00 -08:00
Dav999-v
ddaabb3efe Completely remove Graphics::bprint
Only three deprecated functions remain:
- Graphics::Print
- Graphics::PrintWrap
- Graphics::bigprint

I also fixed multiline transparent textboxes having their outlines
overlap the text itself, and fixed textboxclass::padtowidth assuming
glyph widths of 8 (it made the hints at the start of intermission 1
run offscreen for example)
2023-02-13 23:27:00 -08:00
Dav999-v
a706fb249a Migrate more prints and graphics.len calls to font::
I especially focused on graphics.len and the print calls around them,
because graphics.len calls appear a bit less often, might be overlooked
when migrating print calls (thus possibly using different fonts by
accident) and are often used for some kind of right-alignment or
centering which can be changed into PR_RIGHT or PR_CEN with a different
X anyway.

Notably, I also added a new function to generate these kinds of
sliders: ....[]............

Different languages means that the slider for analogue stick
sensitivity needs to be longer to fit possibly long words for
Low/Medium/High, and then different font sizes means that the longer
slider won't fit onscreen in a language that needs a 12-wide font. So
slider_get() can take a "target width", which dynamically changes the
number of characters depending on the width of them in the interface
font.

I kinda forgot that I could force the 8x8 font instead of adapting the
characters in the slider to the font, and other ideas (like using
different characters or a more graphical progress bar) have been
brought up on Discord, so this might all change again sooner or later.
2023-02-13 23:27:00 -08:00
Dav999-v
48a4e19635 Migrate more prints to font::, determine font for most textboxes
Some textboxes need to be in the level font (like room names, cutscene
dialogue, etc - even in the main game), and some need to be in the
interface font (like when you collect a shiny trinket or crewmate). So
most of these textboxes now have graphics.textboxprintflags(font_flag)
as appropriate.

RoomnameTranslator.cpp is now also migrated to the new print system -
in room name translator mode, the room name is now displayed in the 8x8
font if it's untranslated and the level font if it is.
2023-02-13 23:27:00 -08:00
Dav999-v
6ca83114bc Start using level-specific font where needed, make CJK tweaks
Level text such as room names, text box content, and the contents of
the script editor need to be displayed in the level-specific font, and
tweaked to look right. This involves displaying less lines in the
script editor, making text boxes bigger, displaying some text higher
and some text lower. This is still unfinished, but it's the real start
of a migration to font::print functions!
2023-02-13 23:27:00 -08:00
Dav999-v
159c70dade Move wordwrapping functions and len to Font.cpp/font:: namespace
The following functions were moved directly:
- next_wrap
- next_wrap_s
- string_wordwrap
- string_wordwrap_balanced
- string_unwordwrap

These ones will probably still need get a flags argument, except for
string_unwordwrap (since they need to know what font we're talking
about.

The implementation of graphics.len has also been moved to Font.cpp,
but graphics.len still exists for now and is deprecated.
2023-02-13 23:27:00 -08:00
Misa
fbc9b3ddd7 Use SDL_Point instead of rolling our own point struct
The `point` struct was a relic of ActionScript and was added because of
the Flash 'point' object. However, it seems like Simon Roth didn't
realize that SDL has its own point struct.

With this, `Maths.h` can be un-included from a couple headers, which
exposes the fact that `preloader.cpp` was relying on `Maths.h` being
transitively included from `Graphics.h`.
2023-01-28 23:32:14 -08:00
AllyTally
19b2a317f1 Move from surfaces to the SDL render system
Ever since VVVVVV was initially ported to C++ in 2.0, it has used surfaces from SDL. The downside is, that's all software rendering. This commit moves most things off of surfaces, and all into GPU, by using textures and SDL_Renderer.

Pixel-perfect collision has been kept by keeping a copy of sprites as surfaces. There's plans for pixel-perfect collision to use masks instead of reading pixel data directly, but that's out of scope for this commit.

- `graphics.reloadresources()` is now called later in `main`, because textures cannot be created without a renderer.

- This commit also removes a bunch of surface functions which are no longer needed.

- This also recaches target textures in certain places for d3d9.

- graphics.images was converted to a fixed-size array.

- fillbox and fillboxabs use SDL_RenderDrawRect instead of drawing an outline using four filled rectangles

- Update my name in the credits
2023-01-28 14:36:28 -08:00
Misa
8dc088896f Axe Graphics::ct and Graphics::setcolreal
`ct` was used to be a variable that a color was temporarily stored in
before being passed to a draw function. But this is unnecessary and you
might as well just have a temporary of the color directly. I guess this
was the practice used because temporaries were apparently really bad in
Flash.

setcolreal() was added in 2.3 to do basically the same thing (set it
directly from entities' realcol attributes). But it's no longer needed.

Correspondingly, Graphics::setcol has been renamed to Graphics::getcol
and now returns an SDL_Color, and Graphics::huetilesetcol has been
renamed to Graphics::huetilegetcol for the same reason.

Some functions (notably Graphics::drawimagecol and
Graphics::drawhuetile) were relying on the `ct` to be implicitly set and
weren't ever having it passed in directly. They have been corrected
accordingly.
2023-01-01 20:16:08 -08:00