Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Khris

#1
DOWNLOAD: https://drive.google.com/file/d/1sklK7U1ZNEz_lSmtUxCcwBAPculqVQCt/view?usp=sharing

To use the module, put a button on a GUI, then create a new chat instance:
Code: ags
  globalHandleInt = Chat.Create(btnChat, eFontWestwood [, bgSprite, width, height]);

bgSprite is a sprite slot for the background, it gets auto-tiled if it's smaller than the button. You can also state width and height, in that case the button is resized to those dimensions.

Optionally add sound:
Code: ags
  Chat.SetSound(globalHandleInt, aBlip);

Pass null to disable sound.

To add a message, just call:
Code: ags
  Chat.Add(globalHandleInt, "The message", "sender" [, hour, minute]);

If you put an asterisk at the start of the sender, like "*Alice", the message appears on the right. You can optionally state a timestamp, or omit for user's local time.

Adding a message makes the chat scroll down automatically. You can also scroll using the mousewheel, while hovering over the chat.

The chat is automatically drawn and scrolled if the GUI and button are visible.

It's also possible to prepare multiple messages, just call Chat.Prepare() instead. Show them one by one using Chat.Advance(globalHandleInt); or all at once using Chat.ShowAllPrepared(globalHandleInt);.
(Calling .Add() will simply call .Prepare(), then .Advance(), so make sure you have advanced over all prepared messages before using .Add(), or you will get unexpected results ;) )

It is recommended to call Chat.CleanUp() upon quitting the game, this will delete all the DynamicSprites, avoiding a warnings log in the game folder.

Given that most people will probably want to customize the look of the chat, I've moved the function that draws a message to the very top of the module script.
It gets passed all relevant parameters:
Code: ags
DynamicSprite *CustomMessage(int chatWidth, Alignment align, String author, int hour, int minute, String text, FontType font) 

and must return a new DynamicSprite containing the message.

Preview of default look:
Spoiler
[close]
My example room script: http://pastebin.com/raw/BvruHqr7
#2
Spent a few hours today whipping this up; I tried to test it thoroughly but as you know, some bugs always seep through the cracks. I'd welcome some extensive testing :D

This module is a replacement for the one included in the default game. Be sure to remove the old one if you try this!
I wrote it from scratch but it's set up so the game_start line will still work. You might still want to change that though, the module was primarily written to be used in RPGs together with JoyToKey so ideally it should be set to pressing mode.

Note that the module completely relies on moving and animating the character manually; this allows changing the player's view and speed during movement. The module detects walkable areas pixel-perfectly, so no need to draw them 3 pixels wide any longer.

I've tried to integrate it as far as possible, the module uses several character settings (AdjustSpeedWithScaling, AnimationDelay, DiagonalLoops, MovementSpeedX, MovementSpeedY)

Update: v0.3 - added support for frame sounds (like footsteps)


General control commands:

   KeyboardMovement.SetMode(eKMMode Mode);
Mode is either eKMModePressing or eKeyboardMovement_Tapping (to maintain compatibility with Default Game Global.asc)

   int KeyboardMovement.GetMode()
Returns the current control mode.

   KeyboardMovement.Enable();
   KeyboardMovement.Disable();
Enables/disables the module functionality altogether.

   bool KeyboardMovement.IsEnabled();
Returns whether the module is enabled.
   KeyboardMovement.StopMoving();
In tapping mode, stops the character moving and changes to standing frame. If not in tapping mode, does nothing.


Key binding commands

   KeyboardMovement.SetKey(eKMKey key, eKeyCode k);
Assigns ASCII code k to movement key key.
Example:  KeyboardMovement.SetKey(eKMKeyLeft, eKeyLeftArrow);

   KeyboardMovement.SetRunKey(eKeyCode k);
Assigns ASCII code k to run key.
Example:  KeyboardMovement.SetRunKey(eKMModKeyLeftShift);

   int KeyboardMovement.GetKey(eKMKey key);
Returns ASCII code assigned to movement key key.

   KeyboardMovement.SetMovementKeys(eKMMovementKeys mk);
Assigns scheme mk to movement keys.
The default value is eKMMovementWASD.
Example:  KeyboardMovement.SetMovementKeys(eKMMovementArrowKeys);


Settings commands

   KeyboardMovement.SetRunSpeed(int RunSpeed);
Sets running animation delay to RunSpeed. The default value is 2. Like Character.AnimationSpeed, lower values mean faster movement.

   int KeyboardMovement.GetRunSpeed();
Returns the currently set animation delay of the player's running animation.

   KeyboardMovement.SetLoopDomination(eKMLoopDomination LoopDomination);
Changes which loop the player uses when moving diagonally when there are no diagonal loops.
LoopDomination is either eKMLoopDHorizontal, eKMLoopDVertical or eKMLoopDLast, the default value.

   KeyboardMovement.SetRunView(int RunView, int RunSpeedX, int RunSpeedY);
Allows using a second view for the run-cycle. RunSpeedX and RunSpeedY specify the movement of the character per frame i.e. are determined by the pixels of the run-cycle sprites. In theory it is possible to use the player's NormalView here, however, running by playing the walk animation faster is already implemented by default and increasing the movement values is not recommended because it leads to gliding.

   int KeyboardMovement.GetRunView();
Read back the currently set RunView. If none was set, this returns 0, an invalid view number!

   KeyboardMovement.SetDiagonalFactor(float DiagonalFactor);
Use this to slow down diagonal movement. The default value is 0.707. A value of 1.0 will add horizontal and vertical movement without correction.

   KeyboardMovement.SetEdgeAnimation(bool AnimateAtEdge);
Call this with true as parameter, and the character will continue to animate after having stopped at the edge of the walkable area. It is off by default.

   KeyboardMovement.SetBlockedTurn(bool TurnIfBlocked);
Call this with false as parameter, and the character will no longer face a direction they cannot walk in. It is on by default.

Edit:
Lewis has brought to my attention that the module doesn't work with IdleViews. I fixed the code and added this command:
   KeyboardMovement.SetIdleView(int view, int delay);
Call this instead of player.SetIdleView().


Status functions

   bool KeyboardMovement.Animating();
   bool KeyboardMovement.Moving();
Returns whether the player is currently animating/moving. Use this instead of player.Animating/player.Moving since they won't work with module movement. If edge animations are on, the character might animate but not move!



Phew. After you have imported the module, make sure it is above Global.asc/h. By default, the character will move with WASD and run when you hold down the left shift key.

   DOWNLOAD
SMF spam blocked by CleanTalk